今天安装django,报了“Django - deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver”。查了一番资料,记录下来。
参考链接: Django的web项目部署至Centos7服务器并配置域名访问.
参考链接: Centos7安装Python3和升级SQLite高版本.
参考链接: configure指定编译头文件和库文件路径.
wget https://www.openssl.org/source/openssl-1.1.1d.tar.gz
wget https://www.sqlite.org/2023/sqlite-autoconf-3430000.tar.gz --no-check-certificate
wget https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tgz
Centos 7可使用yum直接升级openssl-devel至1.0.2,正常可以直接装python3.11,如果无法导入ssl可采用下列编译安装openssl。
tar -zxvf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
#./config --prefix=/usr/local/openssl no-zlib #不需要zlib
./config --prefix=/usr/local/openssl
显示结果
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1d (0x1010104fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub <https://github.com/openssl/openssl/issues> ***
*** and include the output from the following command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
*** (If you are new to OpenSSL, you might want to consult the ***
*** 'Troubleshooting' section in the INSTALL file first) ***
*** ***
**********************************************************************
make && make install && make clean
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
# 直接添加link,否则装包的时候经常找不到库,比如装uwsgi
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/local/lib64/libcrypto.so
# pip安装uwsgi时的报错信息。
/usr/bin/ld: 找不到 -lssl
/usr/bin/ld: 找不到 -lcrypto
collect2: 错误:ld 返回 1
*** error linking uWSGI ***
#写入openssl库文件的搜索路径
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf.d/openssl-x86_64.conf
#使修改后的/etc/ld.so.conf生效
ldconfig -v
#查看所需的动态库
ldd /usr/local/openssl/bin/openssl
openssl version -a
# 显示结果
OpenSSL 1.1.1d 10 Sep 2019
yum remove openssl-devel
tar -zxvf sqlite-autoconf-3430000.tar.gz
cd sqlite-autoconf-3430000/
mkdir /usr/local/sqlite3.43
./configure --prefix=/usr/local/sqlite3.43/
make && make install
make clean
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
ln -s /usr/local/sqlite3.43/bin/sqlite3 /usr/bin/sqlite3
#写入sqlite3库文件的搜索路径
echo "/usr/local/sqlite3.43/lib" > /etc/ld.so.conf.d/sqlite3.conf
#使修改后的/etc/ld.so.conf生效
ldconfig -v
#查看所需的动态库
ldd /usr/local/sqlite3.43/bin/sqlite3
sqlite3 --version
# 显示结果
3.43.0 2023-08-24 12:36:59 0f80b798b3f4b81a7bb4233c58294edd0f1156f36b6ecf5ab8e83631d468778c (64-bit)
yum -y install gcc gcc-c++ zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel expat-devel gdbm-devel make
tar -zxvf Python-3.11.5.tgz
cd Python-3.11.5
# 需要配置LD_RUN_PATH指定依赖的搜索目录,LDFLAGS指定库文件路径,CPPFLAGS指定头文件路径
# 如果是编译安装了openssl,需要指定新版路径
./configure LD_RUN_PATH=usr/local/sqlite3.43/lib LDFLAGS="-L/usr/local/sqlite3.43/lib" CPPFLAGS="-I/usr/local/sqlite3.43/include" --prefix=/usr/local/python3.11 --with-openssl=/usr/local/openssl
# 编译并安装 altinstall 不自动创建链接,需要手动创建,建议使用,保障多个版本共存。
make && make altinstall
make clean
make distclean
ln -s /usr/local/python3.11/bin/python3.11 /usr/local/bin/
ln -s /usr/local/python3.11/bin/pip3.11 /usr/local/bin/
python3.11
显示结果
Python 3.11.5 (main, Sep 4 2023, 19:12:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
5、补充说明
之前在Centos6.8上安装Python3.8遇到过死活不能import ssl
参考了https://blog.csdn.net/weixin_30951743/article/details/99891139 .最后成功安装,留做备用信息。
# cd openssl-1.1.1d
# ./config --prefix=$HOME/openssl shared zlib # 这里不同,装了shared zlib 和 $HOME路径
# make && make install
# echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/openssl/lib" >> $HOME/.bash_profile
# source $HOME/.bash_profile
# cat $HOME/.bash_profile
# cd Python-3.8.3
# ./configure --prefix=/usr/local/python3.8 --with-openssl=$HOME/openssl
# make && make altinstall
# make clean
# make distclean
pip3.11 config set global.trusted-host 10.100.224.65
pip3.11 config set global.index-url http://10.100.224.65/root/pypi/+simple/
pip3.11 config set search.index http://10.100.224.65/root/pypi/
或者直接修改文件也可以.
参考: https://www.cnblogs.com/cou1d/p/12403097.html.
mkdir ~/.pip
vim ~/.pip/pip.conf
增加以下内容(以阿里源为例)
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
pip3.11 install pygame -i https://pypi.doubanio.com/simple
python3.11 -m venv /opt/dev/venv/django_test
pip3.11 install django
pip3.11 list
显示结果
Package Version
------------------ ---------
asgiref 3.7.2
certifi 2023.7.22
charset-normalizer 3.2.0
Django 4.2.5
idna 3.4
pip 23.2.1
PyMySQL 1.1.0
requests 2.31.0
setuptools 65.5.0
sqlparse 0.4.4
urllib3 2.0.4
cd /opt/dev
/opt/dev/venv/django_test/bin/django-admin startproject django_test
显示结果
(django_test) [root@centos7-18 django_test]# pwd
/opt/dev/django_test
(django_test) [root@centos7-18 django_test]# ls
db.sqlite3 django_test manage.py
python3.11 manage.py runserver
显示结果
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
September 04, 2023 - 12:11:22
Django version 4.2.5, using settings 'django_test.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.