安装python3
1.安装相关的依赖包:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
1.安装相关的依赖包:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2.下载python3:
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
3.解压:
tar -xf Python-3.6.2.tar.xz
tar -xf Python-3.6.2.tar.xz
4.创建文件夹:
mkdir /usr/local/python3
mkdir /usr/local/python3
5.切换到Python-3.6.2目录
cd Python-3.6.2
cd Python-3.6.2
6.编译安装:
./configure --prefix=/usr/local/python3
make && make install
安装完毕,在/usr/local/目录下就会有python3了
./configure --prefix=/usr/local/python3
make && make install
安装完毕,在/usr/local/目录下就会有python3了
7.添加软链接:
移除旧链接:mv /usr/bin/python /tmp/python
创建新链接:ln -s /usr/local/python3/bin/python3 /usr/bin/python
移除旧链接:mv /usr/bin/python /tmp/python
创建新链接:ln -s /usr/local/python3/bin/python3 /usr/bin/python
8.测试:
python -V 查看输出的版本是不是python3
python2 -V 查看输出的版本是不是python2
python -V 查看输出的版本是不是python3
python2 -V 查看输出的版本是不是python2
9.修改yum 配置:
vi /usr/bin/yum
把 #!/usr/bin/python 修改为#!/usr/bin/python2
vi /usr/bin/yum
把 #!/usr/bin/python 修改为#!/usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把 #!/usr/bin/python 修改为#!/usr/bin/python2
把 #!/usr/bin/python 修改为#!/usr/bin/python2
10.完成:
python3版本就安装完成;同时python2也存在。
python3版本就安装完成;同时python2也存在。
配置pip
1.添加pip3软链接:
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
2.安装python2的pip
sudo yum -y install epel-release
sudo yum -y install python-pip
sudo yum -y install epel-release
sudo yum -y install python-pip
安装python虚拟环境
1.创建一个隐藏目录:
mkdir .virtualenvs
mkdir .virtualenvs
2.安装虚拟环境:
pip3 install virtualenv
pip3 install virtualenvwrapper
pip3 install virtualenv
pip3 install virtualenvwrapper
3.配置环境变量,增加最后两行 :
vim ~/.bashrc
export WORKON_HOME=/root/.virtualenvs
source /usr/local/python3/bin/virtualenvwrapper.sh
vim ~/.bashrc
export WORKON_HOME=/root/.virtualenvs
source /usr/local/python3/bin/virtualenvwrapper.sh
4.加载环境变量:
source ~/.bashrc
>>>如果报错:说 /usr/bin/python 没有 virtualenvwrapper 模块,把 /usr/bin/python 换成 python3,
即 ln -s /usr/local/python3/bin/python /usr/bin/python
source ~/.bashrc
>>>如果报错:说 /usr/bin/python 没有 virtualenvwrapper 模块,把 /usr/bin/python 换成 python3,
即 ln -s /usr/local/python3/bin/python /usr/bin/python
5.创建虚拟环境
mkvirtualenv --python=/usr/bin/python3 myenv
>>>如果报错:说virtualenvwrapper could not find virtualenv in your path ,把/usr/local/python3/bin/vitualenv 链接到
/usr/bin/virtualenv
mkvirtualenv --python=/usr/bin/python3 myenv
>>>如果报错:说virtualenvwrapper could not find virtualenv in your path ,把/usr/local/python3/bin/vitualenv 链接到
/usr/bin/virtualenv
virtualenv的使用:
workon [envname] # 不加参数可以列出环境列表,加环境名称则进入指定环境
lsvirtualenv #列出所有环境
deactivate #注销当前环境
rmvirtualenv envname #删除指定环境
cpvirtualenv #复制环境
cdsitepackages #cd到当前环境的site-packages目录
lssitepackages #列出当前环境中site-packages内容
setvirtualenvproject #绑定现存的项目和环境
wipeenv #清除环境内所有第三方包