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

来源:互联网 发布:网络语言暴力工作视频 编辑:程序博客网 时间:2024/06/05 05:36

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的。

  

  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进入对应的交互式界面

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

  

 

  1.5 py文件指定版本运行

    1.5.1 CMD命令行交互式

      

 

    1.5.2 sublime指定版本运行

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

      

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

# python2

复制代码
#python2{ "cmd":["python2.exe", "-u", "$file"], "path":"C:\\Python27", "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python"}
复制代码

 

# python3

复制代码
#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运行就选择如图

      

 

 

 2. pip的使用

  2.1 安装模块 

# python2

python2 -m pip install 模块名

 # python3

python3 -m pip install 模块名

  2.2 查看版本

# python2

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

 # python3

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

python2 -m pip list

 # python3 

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文件,添加如下文件内容:

[list]format=columns

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

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

 

阅读全文
0 0
原创粉丝点击