ubuntu14.04&&Python 3.6.x&&Django2.2.6安装

安装openssl

apt-get install openssl gcc make libcurl4-openssl-dev 
#libevent-openssl-2.0-5

避免执行命令"pip3 install django"时,
出现“pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available”的错误

参考资料:https://www.cnblogs.com/jasonLiu2018/articles/10730605.html
https://blog.csdn.net/zhengcaihua0/article/details/79681991

下载python源码包Python-3.6.9.tgz

下载路径:https://www.python.org/downloads/release/python-369/

解压、编译、安装Python-3.6.9.tgz

wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
tar -zxvf Python-3.6.9.tgz
cd Python-3.6.9/
#单独编译安装zlib,避免出现“python3 zipimport.ZipImportError: can't decompress data; zlib not availabl”的错误
cd Modules/zlib/
./configure 
make install
#编译、安装Python-3.6.9
cd ../../
./configure 
make 
make test
make install
#建立链接
ln -sf /usr/local/Python-3.6.9/python /usr/bin/python
#检验python的版本
python --version
Python 3.6.9

参考文献:https://blog.csdn.net/jaket5219999/article/details/78583604

安装pip

apt-get install python3-pip
pip3 install --upgrade pip
#使用“pip3 install --upgrade pip”命令,
#避免出现“You are using pip version 18.1, however version 19.3 is available.
#You should consider upgrading via the 'pip install --upgrade pip' command.”的错误

安装Django

#pip3 install django
pip3 install django==2.2.6
django-admin --version
2.2.6
#pip安装PyMySQL,避免出现“ModuleNotFoundError: No module named 'MySQLdb'”错误
pip3 install PyMySQL

python的版本与Django的版本息息相关
在这里插入图片描述

参考文献:https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-framework-on-ubuntu-14-04

部署Django项目

#解压项目压缩包到项目根目录
tar -xf /soft/airemcu_v0.1.tar.gz -C /usr/local/
#更改项目目录下的__init__.py
vim airemcu/__init__.py
    import pymysql
    pymysql.install_as_MySQLdb()
#以上命令避免出现以下问题
#Traceback (most recent call last):
#  File "/usr/local/lib/python3.6/site-#packages/django/db/backends/mysql/base.py", line 15, in <module>
#    import MySQLdb as Database
#ModuleNotFoundError: No module named 'MySQLdb'
#django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
#Did you install mysqlclient?


#更改Django的配置文件base.py,注销以下两行。
vim /usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py
 34 version = Database.version_info
 35 #if version < (1, 3, 13):
 36 #    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
 37 
#并更改Django的配置文件operations.py,将“decode”改为“encode”。
vim /usr/local/lib/python3.6/site-packages/django/db/backends/mysql/operations.py
144         query = getattr(cursor, '_executed', None)
145         if query is not None:
146             query = query.encode(errors='replace')
147         return query
#通过对以上两个文件的注销及更改操作,避免出现以下错误
#  File "/usr/local/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
#    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
#django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.


#配置Django项目目录下的settings.py文件,允许任意客服端访问Django项目并实现数据库连接
vim airemcu/settings.py
 28 
 29 ALLOWED_HOSTS = ["*"]

 85 DATABASES = {
 86     'default': {
 87         'ENGINE': 'django.db.backends.mysql',
 88         'NAME': 'fafa',
 89         'USER': 'root',
 90         'PASSWORD': '123456',
 91         'HOST': '',
 92         'PORT': '',
 93     }
 94 }
#启动Django项目
python manage.py runserver 0.0.0.0:19000

欧克

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值