–
更改阿里云源 在~/.pip/pip.conf文件中添加或修改 mkdir -p ~/.pip cat > ~/.pip/pip.conf<< EOF [global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com EOF 安装python3.8可能使用的依赖 yum install -y python-devel openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel openssl-static libffi-devel 下载python3.8编译安装 到python官网下载https://www.python.org 下载最新版源码,如果使用make install,在系统中将会有两个不同版本的Python在/usr/bin/目录中。这将会导致很多问题,而且不好处理。 把Python3.8安装到 /usr/local 目录 wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz tar xf Python-3.8.5.tar.xz cd Python-3.8.5 ./configure --prefix=/usr/local/python3.8 && make -j4 && make install 更改/usr/bin/python链接 ln -sv /usr/local/python3.8/bin/python3.8 /usr/bin/python3 ln -sv /usr/local/python3.8/bin/pip3 /usr/bin/pip3
如果openssl被重新编译了,需要修改python代码,不然报错
vim Modules/Setup.dist #修改结果如下: # Socket module helper for socket(2) _socket socketmodule.c timemodule.c # Socket module helper for SSL support; you must comment out the other # socket line above, and possibly edit the SSL variable: SSL=/usr/local/openssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto
单独安装pip
下载pip wget https://bootstrap.pypa.io/get-pip.py 安装pip python3 get-pip.py 查看pip版本信息 pip3 -V pip 9.0.1 from /usr/local/python3.8/lib/python3.8/site-packages (python 3.6) 将pip添加到环境变量 ln -sv /usr/local/python3.8/bin/pip3 /usr/bin/pip3
导入sqlite3报错:No module named ‘_sqlite3′ 问题解决
1.、安装上面的依赖包 2、下载sqlite3 wget https://www.sqlite.org/2018/sqlite-autoconf-3220000.tar.gz ./configure --prefix=/usr/local/sqlite3 && make -j4 && make install 3、将库文件添加到环境变量 vim /etc/ld.so.conf /usr/local/sqlite3/lib ldconfig 4、下载上面的py3.6源码,修改 Python-3.6.0文件夹里的setup.py文件 sqlite_inc_paths = [ '/usr/include', '/usr/include/sqlite', '/usr/include/sqlite3', '/usr/local/include', '/usr/local/include/sqlite', '/usr/local/include/sqlite3', '/usr/local/sqlite3/include' ] /usr/local/sqlite3/include是sqlite的安装路径 5、设置环境变量,不然报错 export LD_LIBRARY_PATH=/usr/local/sqlite3/lib 6、重新编译py3.6 ./configure --prefix=/usr/local/python3.8 --enable-loadable-sqlite-extensions && make -j4 && make install
设置path路径
cat > /etc/profile.d/python.sh<< EOF PATH=/usr/local/python3.8/bin:/usr/local/php/sbin:\$PATH export PATH EOF
创建虚拟环境
/usr/local/python3.8/bin/python3.8 -m venv /data/blog
–
–
–
评论前必须登录!
注册