同时安装python2与python3

分类: python

2018-07-16

|

1577

|

评论:0

分享:

编译安装:

下载py3:

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -xzvf Python-3.7.0.tgz
cd Python-3.7.0


安装必要包:

ubuntu:

apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev openssl


centos:
yum install -y zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel

配置安装目录:

./configure --prefix=/usr/local

编译:

make
make install

运行:

python # python2
python3 # python3

pip:

pip  # python2 
pip3  # python3

(注意:升级pip先升级pip3再用pip2升级pip2,否则pip会被pip3替换)

建个虚拟环境

pip3 install virtualenv


virtualenv py2 -p python
virtualenv py3 -p python3


Pyenv安装(推荐)


下载pyenv:

# linux ,mac
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

# mac
brew install pyenv


安装py,可能会缺少某些包,参照前面安装:

pyenv install -v 3.7.2
pyenv install -v 2.7.15

运行:

# 当前shell激活2.7
pyenv shell 2.7.15
python # python2.7

# 永久使用2.7
pyenv global 2.7.15

# 3.7同理
pyenv shell 3.7.2
python # python3.7


更多参考pyenv文档



转载请注明来源

文章:同时安装python2与python3

链接:/article/28

作者:gojuukaze

标签: python
本文共 0 个回复

发表评论 (对文章评论)

captcha