linux上同时安装python2.7和python3.6

2018-08-27  本文已影响0人  逍遥_yjz

今天装了CentOS服务器,为其装python3.6的环境,具体步骤如下:
自已已经提前安装python2.7,
注:centos 安装基础
转移安装包:
生成requirements.txt文件

pip freeze > requirements.txt

安装requirements.txt依赖

pip install -r requirements.txt
1. 安装可能需要的依赖包:
2. 下载安装包
解压
创建python3.6文件夹
进入解压后的文件夹
3. 指定安装路径,编译安装
4. 添加环境变量

第四步,添加也不可以,失败,直接跳到二标题。

export PATH=$PATH:/usr/local/python3.6/bin

5. 重载环境变量

上面的第四步可以使用一下命令替换:

export PATH=/usr/local/python3.6/bin:$PATH

$ source /etc/profile
好了,通过以上的步骤就可以实现python3.6的安装了,现在在界面输入python3 就可以打开python3.6.0 了,直接输入python会是系统自带的 python2.7。

6. 修改pip3

python3 -m pip install --upgrade pip --force-reinstall,显示重新安装成功。

二、重启连接服务器使用python3失败

1. 建立python3的软链

ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3

2. 并将/usr/local/python3.6/bin加入PATH

vim ~/.bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3.6/bin
export PATH

按ESC,输入:wq回车退出。

修改完记得执行行下面的命令,让上一步的修改生效:

检查Python3及pip3是否正常可用:

# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
3. 不行的话尝试创建一下pip3的软链接
  1. 图像识别环境部署
  2. centos python3 的 卸载 删除

三、更换pip 安装源

pip国内的一些镜像
  阿里云 https://mirrors.aliyun.com/pypi/simple/
  中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
  豆瓣(douban) http://pypi.douban.com/simple/
  清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
  中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

修改源方法:
临时使用:
可以在使用pip的时候在后面加上-i参数,指定pip源

pip install opencv-python -i  https://mirrors.aliyun.com/pypi/simple

Linux:
永久使用可以这样
修改 ~/.pip/pip.conf 文件,如下

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

出现如下报错:
E212: Can't open file for writing
问题解决:
因为不存在.pip这个文件夹所以会存在这个问题,新建文件夹~/.pip就可以解决了.

 mkdir ~/.pip
 vim ~/.pip/pip.conf

Windows:
接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下:

[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
上一篇 下一篇

猜你喜欢

热点阅读