可搜索,可注册,可登录,致敬逗比大佬!尽在救援版逗比根据地 dbgjd.com
投稿文章 | 广告合作 | Telegram 群组 / 公告频道 / 使用教程

Python2.7和3.5双版本共存和pip的使用

News tysonrapz1984 567℃ 0评论

1. Python2.7和3.5并存

  1.1 安装

安装自不必多说,先装2.7,再装3.5.

说下安装的目录:Py3.5和Py2.7默认的安装目录是不一样的,按默认的来就好,不用管。

Python2.7: C:/Python27

Python3.5: C:/Users/Administrator/AppData/Local/Programs/Python/Python35

 

  1.2 环境变量

先安装2.7再安装3.5的好像是3.5的会替换到原来2.7添加到Path的路径,所以要自己在手动添加2.7的。

Python2.7和3.5双版本共存和pip的使用

  1.3 改名

使用前,到 C:/Python27  将python.exe,pythonw.exe 改为python2.exe,pythonw2.exe

  C:/Users/Administrator/AppData/Local/Programs/Python/Python35 python.exe,pythonw.exe 改为python3.exe,pythonw3.exe

  1.4 CMD进入对应的交互式界面

改完名后,就方便区分启动了。

Python2.7和3.5双版本共存和pip的使用

 

  1.5 py文件指定版本运行

    1.5.1 CMD命令行交互式

Python2.7和3.5双版本共存和pip的使用

 

    1.5.2 sublime指定版本运行

先按箭头顺序打开 untitled.sublime-build  编辑

Python2.7和3.5双版本共存和pip的使用

分两次操作,写入如下代码(根据自己的实际路径和python名更改cmd命令和路径,注意路径是’//

# python2

Python

1
2
3
4
5
6
7
8
#python2
 
{
“cmd”:[“python2.exe”, “-u”, “$file”],
“path”:“C://Python27”,
“file_regex”: “^[ ]*File /”(…*?)/”, line ([0-9]*)”,
“selector”: “source.python”
}

 

# python3

Python

1
2
3
4
5
6
7
8
#python3
 
{
“cmd”:[“python3.exe”, “-u”, “$file”],
“path”:“C://Users//Administrator//AppData//Local//Programs//Python//Python35”,
“file_regex”: “^[ ]*File /”(…*?)/”, line ([0-9]*)”,
“selector”: “source.python”
}

 

注意的时,储存路径(根据各位的实际情况来):C:/Users/Administrator/AppData/Roaming/Sublime Text 3/Packages/User

然后用Ctrl+B运行的时候,就在Tools-Build System中选择相应的版本即可

如我要用python2运行就选择如图

Python2.7和3.5双版本共存和pip的使用

 

 

 2. pip的使用

  2.1 安装模块

# python2

1
python2 m pip install 模块名

# python3

1
python3 m pip install 模块名

  2.2 查看版本

# python2

1
2
python2 m pip version
#pip 9.0.1 from C:/Python27/lib/site-packages (python 2.7)

# python3

1
2
python3 m pip version
#pip 8.1.1 from C:/Users/Administrator/AppData/Local/Programs/Python/Python35/lib/site-packages (python 3.5)

 

  2.3 查看库列表

# python2

1
python2 m pip list

# python3

1
python3 m pip list

 

python2查看list的时候,当提示如下:

DEPRECATION: The default format will switch to columns in the future. You can use –format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.

解决方法:自己创建%APPDATA%/pip/pip.ini文件,添加如下文件内容:

Python

1
2
[list]
format=columns

 注:%APPDATA% 可以通过运行,输入,回车进入

解决完,list由左边变成右边的

Python2.7和3.5双版本共存和pip的使用

转载请注明:逗比根据地 » Python2.7和3.5双版本共存和pip的使用

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址