Pre:
环境: Centos7 64位
安装py3:
py3版本:3.6.3
1 2
| yum install zlib-devel bzip2-devel openssl-devel ncurses-devel -y
|
1 2
| yum install gcc-c++ gcc -y
|
1 2
| wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
|
1 2
| tar xf Python-3.6.3.tar.xz -C /usr/local/src/
|
1 2 3 4
| cd /usr/local/src/Python-3.6.3/ ./configure --prefix=/usr/local/python3 make -j 4 && make install
|
安装成功后提示
1 2 3 4
| ln -s /usr/local/python3/bin/python3.6 /usr/local/bin/python3 ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
|
1 2
| pip3 install --upgrade pip
|
搞定.
同时再安装py3.9:
1 2
| wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
|
1 2
| tar xf Python-3.9.5.tgz -C /usr/local/src/
|
1 2 3 4
| cd /usr/local/src/Python-3.9.5/ ./configure --prefix=/usr/local/python3.9 make -j 4 && make install
|
1 2 3 4
| ln -s /usr/local/python3.9/bin/python3 /usr/local/bin/python3.9 ln -s /usr/local/python3.9/bin/python3 /usr/bin/python3.9 ln -s /usr/local/python3.9/bin/pip3 /usr/bin/pip3.9
|
1 2
| pip3.9 install --upgrade pip
|
注意路径,然后不要把原来的另一个python3版本的覆盖了就好。
安装py2:
py2版本:2.7.13
1 2 3
| yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
|
1 2 3
| wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz tar -zxvf Python-2.7.13.tgz
|
1 2 3 4 5
| cd Python-2.7.13 ./configure --prefix=/usr/local make make altinstall
|
1 2 3 4 5
| mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python2.7 /usr/bin/python
|
1 2 3 4 5 6
| wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
ln -s /usr/local/bin/pip2.7 /usr/bin/pip
|
修改yum配置:
1 2 3 4 5 6 7
|
ll /usr/bin/yum*
vi /usr/bin/yum*
|
1 2 3
| vi /usr/libexec/urlgrabber-ext-down
|
包的迁移:
1 2 3
| pip2 freeze > py2requirements.txt pip3 freeze > py3requirements.txt
|
1 2 3 4
| pip install -r requirements.txt
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
|
注意:pip会顺序从列表上安装下来,遇到某个有问题的包后,会退出.后面的包不会被安装到.
一些无法或很难安装的包,可以尝试通过复制来迁移
1 2 3 4 5
| >>> import sys >>> print sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
|
pip其他使用场景:
1 2 3 4 5
| while read requirement; do sudo pip3 install $requirement; done < requirement.txt
while read requirement; do sudo pip2 install $requirement -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mir rors.aliyun.com; done < py2requirements.log
|
refs: