森哥瞧世界

您现在的位置是:首页>文档内容页

文档详情

同时安装python2与python3

jeson 2020-01-13 17:31:16 Python9221
同时安装python2与python3

编译安装:

下载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 mysql-devel python-devel 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 mysql-devel python-devel zlib zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel gcc gcc-c++

配置安装目录:

./configure --prefix=/usr/local --enable-optimizations

编译:

make
make install

运行:

python # python2
python3 # python3

安装pip

yum install -y python-pip
pip install --upgrade pip

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

配置运行环境

vi /etc/profile
export PATH="/root/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
source /etc/profile

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

pyenv install -v 3.7.2
pyenv install -v 2.7.15

注:pyenv install -v 2.7.15 时失败,通过下面方法解决。

wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tar.xz
mkdir ~/.pyenv/cache/
cp Python-2.7.15.tar.xz ~/.pyenv/cache/
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

安装pipenv

pip install pipenv

或者

python3 -m pip install pipenv

或者

python2 -m pip install pipenv

通过查看pipenv版本来确认是否安装成功

pipenv --version

国内的PyPI镜像源

pipenv install --dev --pypi-mirror https://mirrors.aliyun.com/pypi/simple


文章评论

Cancel the reply
Login Participate In Comments

Review(