文章目录
- 1、CentOS安装OpenSSL1.1.1(前置环境)
- 2、CentOS安装 Python 3.10
- 3、创建虚拟环境
- 4、运行Django项目
1、CentOS安装OpenSSL1.1.1(前置环境)
编译安装Python3.10时需要openssl1.1.1
查看当前版本 & 删除openssl1.0
openssl version
yum remove openssl
切换目录,下载安装包,解压并进入目录
cd /opt
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz --no-check-certificate
tar -zxf openssl-1.1.1n.tar.gz
cd openssl-1.1.1n
安装依赖
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y perl-CPAN
perl -MCPAN -e shell
cpan[1]> install IPC/Cmd.pm
配置,编译,安装,软连接
./config --prefix=/usr/local/openssl
make -j 2
make install
ln -sf /usr/local/openssl/bin/openssl /usr/bin/openssl
环境变量
vim /etc/ld.so.conf
在文件末尾添加一行代码:
/usr/local/openssl/lib
保存:
vim : q
使之生效:
ldconfig -v
验证版本:
openssl version
2、CentOS安装 Python 3.10
基础环境配置升级
sudo yum -y update
sudo yum -y groupinstall “Development tools”
sudo yum -y install openssl-devel libffi-devel bzip2-devel
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 -y libffi-devel zlib1g-dev
yum install zlib* -y
切换目录, 下载安装包, 解压并进入源码目录
cd /opt
wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tgz
tar xvzf Python-3.10.4.tgz
cd Python-3.10.4
配置编译并且安装,创建软连接,参考
./configure --enable-optimizations --with-openssl=/usr/local/openssl-1.1.1 --with-openssl-rpath=auto
./configure --with-openssl=/usr/local/openssl-1.1.1 --with-openssl-rpath=auto
make clean
make -j && make install
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
报错:make[1]: *** [pybuilddir.txt] Error 1 make[1]: Leaving directory `/opt/Python-3.10.4' make: *** [profile-opt] Error 2
在低版本的gcc版本中带有 --enable-optimizations 参数时会出现上面问题
gcc 8.1.0修复此问题
1、升级gcc至8.1.0【不推荐】
2、./configure参数中去掉 --enable-optimizations
验证
python3 --version
默认的centos7是没有安装pip,先添加epel扩展源
yum -y install epel-release
yum install python-pip
更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用
vi /usr/bin/yum
把第一行的#! /usr/bin/python 修改为如下
#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python2
3、创建虚拟环境
python3创建虚拟环境
sudo yum install python3-pip
sudo /usr/local/bin/python3 -m pip install --upgrade pip
sudo /usr/local/bin/python3 -m pip install setuptools --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
成功安装:
sudo pip3 install virtualenv --user -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
-i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
-i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
报错惨案:
https://blog.csdn.net/JIEJINQUANIL/article/details/102816801
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
进入(cd)选择的目录搭建一个虚拟环境, 选择指定一个Python解释器
virtualenv cetnos_env
virtualenv -p /usr/bin/python3.10 cetnos_env
将会在当前的目录中创建一个名venv的文件夹,这是一个独立的python运行环境,包含了Python可执行文件, 以及 pip库的一份拷贝,但第三方包需要重新安装。
要开始使用虚拟环境,其需要被激活:
source env/bin/activate
deactivate
4、运行Django项目
基础版本,pycharm
本地运行
python manage.py runserver
云端运行(允许外网访问):
ALLOWED_HOSTS = ['*']
python manage.py runserver 0.0.0.0:8000
python3 manage.py runserver 0.0.0.0:8000
嗯,sqlite版本check不通过,就删删删
关于django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3
def check_sqlite_version():
if Database.sqlite_version_info < (3, 9, 0):,版本改掉
然后 # deterministic=True,注释掉
路径版本
本地运行:
C:\_projetcs\Pycharm\fmyy_django\fmyy_django\env1\Scripts\python.exe manage.py runserver
Centos:
/www/wwwroot/fmyy_django/centos_env/bin/python3.10 manage.py runserver 0.0.0.0:8000
依赖安装:
pip install -r requirements.txt
本地
C:\_projetcs\Pycharm\Python310\Scripts\pip.exe install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
虚拟
/www/wwwroot/fmyy_django/centos_env/bin/pip3 install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
真实
python3 -m pip install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
# 报错:(更新sqlite)
s.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).
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
'3.36.0'
https://www.cnblogs.com/yoyo1216/p/14927862.html
https://blog.csdn.net/ldq_sd/article/details/123850041
#from sqlite3 import dbapi2 as Database #注释它
from pysqlite3 import dbapi2 as Database #新加这段代码
然后执行
export LD_LIBRARY_PATH="/usr/local/lib"