一个方法是使用virtuallen环境,另一方法是使用pyenv
virtuallen
使用virtuallen管理多个python版本,需要先安装多个python环境
1. ubuntu下源代码安装python
从http://www.python.org/download/下载源文件。
编译安装
tar zxvf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/local/python-2.7.6 #重要,指定python的安装路径,可以自己设置。
make
sudo make install
修改Python软链
修改Python软链的目的是使ubuntu的默认的python环境是你所安装的环境,这一步不是必须的。默认python命令是在/usr/bin/目录下,需要在这里把软链修改成2.7的版本,顺便建立一个2.4的软链。
mv /usr/bin/python /usr/bin/python2.4 #原来的软链改名为python2.4
ln -s /usr/local/python-2.7.6/bin/python /usr/bin/python
#新建一个python的软链,链接到编译安装的python的bin目录中的python程序
安装使用virtuallen
可能需要安装pip
sudo pip install virtualenv
错误:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
参考这篇文章:https://blog.csdn.net/jeryjeryjery/article/details/77880227
解决方法就是重新编译:
cd Python-3.6.2
./configure --with-ssl
make
sudo make install
给出了警告:
configure: WARNING: unrecognized options: --with-ssl
换另外一种方法ssl module in Python is not available的解决方法和https://stackoverflow.com/questions/41328451/ssl-module-in-python-is-not-available-when-installing-package-with-pip3
最后的执行pip install virtualenv出错:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
参考这篇文章:https://blog.csdn.net/tintinetmilou/article/details/80091630