一群井、安裝Python3
依賴
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install gcc -y-
安裝python
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
mv Python-3.7.4.tgz /usr/local/
mkdir /usr/local/python3
cd /usr/local/
tar -xvf Python-3.7.4.tgz
cd /usr/local/Python-3.7.4/
./configure --prefix=/usr/local/python3
make && make installModuleNotFoundError: No module named '_ctypes'
哑了,這是因為缺少依賴包libffi-devel
,解決方法可參考https://blog.csdn.net/CUFEECR/article/details/103093951
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
- 安裝pip3
yum install openssl-devel -y
yum install zlib-devel -y
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
sudo python3 setup.py build
sudo python3 setup.py install
export PATH=$PATH:/usr/local/python3/bin
安裝Django
- 設(shè)置源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ - 安裝
pip3 install Django - 創(chuàng)建項目
django-admin startproject App1
python3 manage.py runserver
參考https://docs.djangoproject.com/zh-hans/4.0/intro/tutorial01/
異常:django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
解決:更新sqlite
cd /usr/local/src
wget http://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
tar -zxvf sqlite-autoconf-3360000.tar.gz
cd sqlite-autoconf-3360000
./configure --prefix=/usr/local/sqlite
make && make install
mv /usr/bin/sqlite3 /usr/bin/sqlite3_bak
cd /usr/local/sqlite/bin/
ln -s sqlite3 /usr/bin/sqlite3
vim /etc/profile
export LD_LIBRARY_PATH="/usr/local/sqlite/lib"
source /etc/profile
import sqlite3
sqlite3.sqlite_version
如果異常:django.db.utils.NotSupportedError: deterministic=True requires SQLite
pip3 install pysqlite3
pip3 install pysqlite3-binary
vim /usr/local/python3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py
from sqlite3 import dbapi2 as Database (注釋掉這段)
from pysqlite3 import dbapi2 as Database #改成pysqlite3