Centos 使用 virtualenv 建设 python 多环境
在 python 开发中经常会使用多个版本的 python 语言或者依赖库,使用 virtualenv 可以解决这种多版本依赖的问题,可以给每一套系统搭建单独的python 环境,系统间互不干扰。
cd Python-3.8.0
./configure --with-ssl --prefix=/usr/local/python3.8/
make && make install
ln -s /usr/local/python3.8/bin/python3 /usr/local/bin/python3.8
ln -s /usr/local/python3.8/bin/pip3 /usr/local/bin/pip3.8
yum install -y zlib zlib-dev openssl-devel sqlite-devel bzip2-devel libffi libffi-devel gcc gcc-c++
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=/usr/local/openssl shared zlib
make && make install
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openssl/lib" >> ~/.bash_profile
source ~/.bash_profile
pip3.8 install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3.8 install virtualenv -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
yum install python-virtualenv
[ ]
Already using interpreter /usr/local/python3.8/bin/python3.8
Using base prefix '/usr/local/python3.8'
New python executable in /data1/pyenv.py38/bin/python3.8
Also creating executable in /data1/pyenv.py38/bin/python
Installing pip, wheel...
done.
[root@10_1_162_39 ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias py38='source /data1/pyenv.py38/bin/activate' # 新增
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
[root@10_1_162_39 data1]# source ~/.bashrc
[ ]
(pyenv.py38) [root@10_1_162_39 data1]
pip 19.3.1 from /data1/pyenv.py38/lib/python3.8/site-packages/pip (python 3.8)
(pyenv.py38) [root@10_1_162_39 data1]# deactivate
[root@10_1_162_39 data1]#
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
pip3.8 install virtualenvwrapper