目錄:
1:linux用django startproject報錯
2:python manage.py runserver報錯:SQLite 3.8.3 or later is required (found 3.7.17)
3:無法直接使用pip3或pip命令
4:安裝uwsgi報錯:plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
5:安裝uwsgi報錯:ModuleNotFoundError: No module named '_ctypes'
6:uwsgi啟動報錯:probably another instance of uWSGI is running on the same address
7:安裝uwsgi報錯:Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-zcnqe9e2/uwsgi/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-f2pzir0h-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-zcnqe9e2/uwsgi/
8:域名/admin報錯:Invalid block tag on line 23: 'translate'
坑1:linux用django startproject報錯??
[root@iZo4t6je6mwbb8Z django]# django-admin.py startproject demo1
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/bin/django-admin.py", line 5, in <module>
from django.core import management
ImportError: No module named django.core
原因:
linux默認(rèn)是有python2的阳惹,但我又安裝了python3砚著,django是在python3的lib里筛婉,所以執(zhí)行django-admin.py startproject learn辩棒,調(diào)用的python環(huán)境是python2的涝影,所以找不到core.management嗤详。
解決方案:
cd /usr/bin
mv python python2 #原先的python是python2.7的軟連接
mv python3 python #現(xiàn)在修改python為python3
實際演示:
[root@iZo4t6je6mwbb8Z django]# cd /usr/bin
[root@iZo4t6je6mwbb8Z bin]# mv python python2
mv: overwrite ‘python2’? y
[root@iZo4t6je6mwbb8Z bin]# mv python3 python
[root@iZo4t6je6mwbb8Z bin]# cd /home/liujia/django
[root@iZo4t6je6mwbb8Z django]# django-admin.py startproject demo1
[root@iZo4t6je6mwbb8Z django]# ls
demo1
[root@iZo4t6je6mwbb8Z django]# cd demo1
[root@iZo4t6je6mwbb8Z demo1]# ls
demo1 manage.py
[root@iZo4t6je6mwbb8Z demo1]#
坑2:python manage.py runserver報錯:SQLite 3.8.3 or later is required (found 3.7.17)
原因:
阿里云自帶的centos的sqlite版本低了
解決方案:
#更新SQLite 3
#獲取源代碼(在主目錄中運行)
[root@djangoServer ~]# cd ~
[root@djangoServer ~]# wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]# tar -zxvf sqlite-autoconf-3270200.tar.gz
#構(gòu)建并安裝
[root@djangoServer ~]# cd sqlite-autoconf-3270200
[root@djangoServer sqlite-autoconf-3270200]# ./configure --prefix=/usr/local
[root@djangoServer sqlite-autoconf-3270200]# make && make install
[root@djangoServer sqlite-autoconf-3270200]# find /usr/ -name sqlite3
/usr/bin/sqlite3
/usr/lib64/python2.7/sqlite3
/usr/local/bin/sqlite3
/usr/local/python3/lib/python3.7/site-packages/django/db/backends/sqlite3
/usr/local/python3/lib/python3.7/sqlite3
[root@djangoServer sqlite-autoconf-3270200]#
#不必要的文件礁遣,目錄刪除
[root@djangoServer sqlite-autoconf-3270200]# cd ~
[root@djangoServer ~]# ls
anaconda-ks.cfg sqlite-autoconf-3270200 sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]#
[root@djangoServer ~]# rm -rf sqlite-autoconf-3270200.tar.gz
[root@djangoServer ~]# rm -rf sqlite-autoconf-3270200
#檢查版本
## 最新安裝的sqlite3版本
[root@djangoServer ~]# /usr/local/bin/sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
[root@djangoServer ~]#
## Centos7自帶的sqlite3版本
[root@djangoServer ~]# /usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@djangoServer ~]#
## 可以看到sqlite3的版本還是舊版本矾削,那么需要更新一下郎逃。
[root@djangoServer ~]# sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
[root@djangoServer ~]#
## 更改舊的sqlite3
[root@djangoServer ~]# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
## 軟鏈接將新的sqlite3設(shè)置到/usr/bin目錄下
[root@djangoServer ~]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
## 查看當(dāng)前全局sqlite3的版本
[root@djangoServer ~]# sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
[root@djangoServer ~]#
#將路徑傳遞給共享庫
# 設(shè)置開機自啟動執(zhí)行哥童,可以將下面的export語句寫入 ~/.bashrc 文件中,如果如果你想立即生效褒翰,可以執(zhí)行source ?/.bashrc 將在每次啟動終端時執(zhí)行
[root@djangoServer ~]# export LD_LIBRARY_PATH="/usr/local/lib"
#檢查Python的SQLite3版本
[root@djangoServer ~]# ipython3
Python 3.7.1 (default, May 3 2019, 09:55:04)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sqlite3
In [2]: sqlite3.sqlite_version
Out[2]: '3.27.2'
In [3]: exit
[root@djangoServer ~]#
#啟動開發(fā)服務(wù)器
[root@djangoServer ~]# cd /work/
[root@djangoServer work]# ls
db.sqlite3 manage.py polls test_django
[root@djangoServer work]# python3 manage.py runserver
坑3:無法直接使用pip3或pip命令
原因:
未知
解決方案1:
使用python -m pip代替
解決方案2:另一個懷疑能解決的方案是安裝libffi-devel贮懈,然后重新從./configure這一步開始重新安裝python
yum install libffi-devel
坑4:安裝uwsgi報錯:plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
原因:
未知
解決方案:
yum install python-devel.x86_64
坑5:安裝uwsgi報錯:ModuleNotFoundError: No module named '_ctypes'
yum install libffi-devel
從./configure這一步開始重新安裝python
坑6:uwsgi啟動報錯:probably another instance of uWSGI is running on the same address
可以用命令殺掉這個端口在重啟:
sudo fuser -k 8080/tcp
坑7:安裝uwsgi報錯:Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-zcnqe9e2/uwsgi/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-f2pzir0h-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-zcnqe9e2/uwsgi/
yum install python3-devel -y
坑8:Invalid block tag on line 23: 'translate'
vi 到具體文件,執(zhí)行替換命令:
:%s#translate#trans#g