ubuntu如何安装django(ubuntu如何安装搜狗输入法)

导读:很多朋友问到关于ubuntu如何安装django的相关问题,本文首席CTO笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!

如何在ubuntu 12.04下搭建Python Django环境

首先Ubuntu自带Python 然后 安装Django

这个是 安装 配置 使用 Nginx Uwsgi 来配置Django

照着 一步步来就行 很简单 生产环境使用

ubuntu如何安装django(ubuntu如何安装搜狗输入法)  第1张

如何在ubuntu 下配置Django和apache + mod

参考一下:

Apache是全球使用率最高的、开源的一个Web服务端软件,现在介绍一下如何在Ubuntu 14.04上安装和配置Apache。

工具/原料

Ubuntu 14.04

方法/步骤

命令行安装Apache

打开"终端窗口",输入"sudo apt-get install apache2"--回车--输入"root用户的密码"--回车--输入"y"--回车,安装完成

默认的网站根目录的路径

Apache安装完成后,默认的网站根目录是"/var/www/html",在终端窗口中输入"ls /var/www/html"--回车--在网站根目录下有一个"index.html"文件,在ie浏览器中输入"127.0.0.1"--回车,就可以打开该页面。

Apache的第一个配置文件apache2.conf的路径

在终端窗口中输入"ls /etc/apache2"--回车--有一个"apache2.conf"的配置文件。

Apache的第二个配置文件000-default.conf的路径

在终端窗口中输入"ls /etc/apache2/sites-available"--回车--有一个"000-default.conf"的配置文件。

修改网站的根目录

1、在终端窗口中输入"sudo vi /etc/apache2/apache2.conf"--回车--找到"Directory /var/www/"的位置--更改"/var/www/"为新的根目录就可以了。

2、在终端窗口中输入"sudo vi /etc/apache2/sites-available/000-default.conf"--回车--找到"DocumentRoot /var/www/html"的位置--更改"/var/www/html"为新的根目录就可以了,这里我把它更改为"/var/www/"。

重启Apache

在终端窗口中输入"sudo /etc/init.d/apache2 restart"--回车--"输入root用户密码"--回车--重启成功。

复制"index.html"文件到"/var/www"目录下

在终端窗口中输入"cp /var/www/html/index.html /var/www/"--回车--输入"ls /var/www"--回车--有一个"index.html"文件,复制成功。

测试更改网站根目录是否成功

在"火狐浏览器"中输入"127.0.0.1"--能访问到"index.html"文件--更改成功

ubuntu怎么部署django

记录一次在全新服务器下配置Django项目说明:

Linux操作系统:Ubuntu 16.04

Django版本:1.8.7

Python版本:2.7.12

运行模式:Ubuntu+Django+Apache2+Mod_wsgi

Apache2配置文件:sudo vi /etc/apache2/apache2.conf

Apache2错误日志:cat -n /var/log/apache2/error.log

Apache2命令:

启动:sudo /etc/init.d/apache2 start

重启:sudo /etc/init.d/apache2 restart

停止:sudo /etc/init.d/apache2 stop

配置过程如遇到错误,请仔细检查前面每一步是否有完全按照教程来执行。

1.安装Django

a) sudo apt-get install python-pip

b) sudo pip install Django==1.10.5

2.安装Apache2

a) sudo apt-get install apache2

3.安装libapache2-mod-wsgi

a) sudo apt-get install libapache2-mod-wsgi

4.创建项目及应用

a) 创建项目

django-admin startproject 项目名称

b) 创建应用(如果有应用就上传到项目目录下,否则创建)

python manage.py startapp 应用名称

5.项目和应用建好后给予权限

a) chown -R www-data:www-data 项目名称

6.配置Apache2

a) sudo vi /etc/apache2/apache2.conf

169-177行是我添加的内容

169 Directory /home/z/product/Code(改为自己的项目目录)

170 Options Indexes FollowSymLinks

171 AllowOverride None

172 Require all granted

173 /Directory

174 WSGIScriptAlias / /home/z/product/Code/Code/wsgi.py(改为自己的项目文件)

175 WSGIPythonPath /home/z/product/Code(改为自己的项目文件)

176 Alias /static/ /home/z/product/Code/business/static/(改为自己的项目内的应用)

177 Alias /static/ /home/z/product/Code/yyl/static/(改为自己的项目内的应用)

169-175行的功能为添加项目至Apache

176和177行是为了加载应用内/static/目录内的静态资源

错误及解决方案:

下面错误可能只是自己当前项目中所遇到的错误,其他项目请忽略。

问题一:ImportError: No module named celery

sudo pip install git+

问题二:No module named PIL.ImImagePlugin

sudo apt-get install python-imaging

问题三:No module named requests

sudo pip install requests

问题四:No module named dss.Serializer

sudo pip install django-simple-serializer

Ubuntu 14.04下Django+MySQL安装部署全过程

Ubuntu 16.04下安装部署 Nginx+uWSGI+Django1.9.7

Django 的详细介绍:请点这里

Django 的下载地址:请点这里

本文永久更新链接地址:

django安装各种包报错

Ubuntu新环境下搭建django rest api时安装MySQL-python 报错。

需要安装(sudo)apt-get install python-dev

python-dev 是必须的  ---- error: Python.h

你需要自己安装一个源外的python类库, 而这个类库内含需要编译的调用python api的c/c++文件

你自己写的一个程序编译需要链接libpythonXX.(a|so)

(注:以上不含使用ctypes/ffi或者裸dlsym方式直接调用libpython.so)

其他正常使用python或者通过安装源内的python类库的不需

Installing collected packages: MySQL-python

Running setup.py install for MySQL-python ... error

Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZzcKHT/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Ur_CBU-record/install-record.txt --single-version-externally-managed --compile:

running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

copying _mysql_exceptions.py - build/lib.linux-x86_64-2.7

creating build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/__init__.py - build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/converters.py - build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/connections.py - build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/cursors.py - build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/release.py - build/lib.linux-x86_64-2.7/MySQLdb

copying MySQLdb/times.py - build/lib.linux-x86_64-2.7/MySQLdb

creating build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/__init__.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/CR.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/FIELD_TYPE.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/ER.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/FLAG.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/REFRESH.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

copying MySQLdb/constants/CLIENT.py - build/lib.linux-x86_64-2.7/MySQLdb/constants

running build_ext

building '_mysql' extension

creating build/temp.linux-x86_64-2.7

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o

_mysql.c:29:20: fatal error: Python.h: No such file or directory

#include "Python.h"

^

compilation terminated.

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ZzcKHT/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Ur_CBU-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ZzcKHT/MySQL-python/

腾讯云python系列之部署Django流程

我的是centos系统

我们通过腾讯的控制台的登录按钮,进入到远程登录的界面,如图1为腾讯云的控制台界面。图2为登录以后的密码输入窗口

进入登录界面以后,会是图3这样子的情况,我们输入ls,会发现没有任何文件, 输入pip list 会提示没有安装pip,而输入python时,会显示默认安装了python2.7.5版本

一、首先我们要安装pip,根据自己的系统自行选择

centos类系统: sudo yum install python python-pip

ubuntu类系统:sudo apt-get install python python-pip

安装好以后pip list一下,看看都有哪些python安装包

二、安装django

我安装的Django版本为1.9.8的,根据自己的情况,更改后面的版本号

sudo pip install Django ==1.9.8

可能会出现图4这样的问题,原因是我们pip 版本太低,直接按照提示升级我们的pip

更新了pip以后,安装可能会出现如图5这样的问题,我们不要在==两边加空格,因为加空格会导致不识别django的版本。

安装完以后你会发现自己找不到Django放在哪里了,其实我的django被安装在了

/usr/lib/python2.7/site-packages/

并且我们要执行创建django的命令在django的bin目录下,如图6

/usr/lib/python2.7/site-packages/django/bin

进入到该目录下,运行django-admin.py startproject FirstProject,创建出FirstProject的项目。就会在该目录下创建出FirstProject这个项目,进入项目,运行python manage.py runserver

问题来了,我们运行以后,不要点击,这个是进不去的,我们应该通过腾讯云的公网ip来访问网站,但又有同学发现通过公网的ip也无法访问我们的网站,这是因为自己的腾讯云没有打开相应的端口,所以无法访问。开放端口在安全组这个选项,如图7

进入安全组,新建我们的开放端口,我开放的是80端口。如图8

开放端口后,我们重新python manage.py runserver 0.0.0.0:80,如图9

通过公网ip,就可以直接访问我们的网站了。如图10

结语:以上就是首席CTO笔记为大家整理的关于ubuntu如何安装django的全部内容了,感谢您花时间阅读本站内容,希望对您有所帮助,更多关于ubuntu如何安装django的相关内容别忘了在本站进行查找喔。

以上内容为新媒号(sinv.com.cn)为大家提供!新媒号,坚持更新大家所需的互联网后端知识。希望您喜欢!

版权申明:新媒号所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,不声明或保证其内容的正确性,如发现本站有涉嫌抄袭侵权/违法违规的内容。请发送邮件至 k2#88.com(替换@) 举报,一经查实,本站将立刻删除。

(0)
上一篇 2023-09-23 13:06
下一篇 2023-09-23 13:06

相关推荐

发表回复

登录后才能评论