windows同时安装python2和python3

系统之前安装了python2.7,现在准备装个python3.6

 

1:首先下载一个python3.6适合windows32位的包python-3.6.5.exe

然后直接默认双击安装,安装的时候勾选add to path

默认安装路径C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32

进入这个路径把python.exe修改成python3.exe这样在dos下直接python3,就可以进入python3的环境了,

怎么进入python2呢?默认输入python

 

2 关键是怎样使用python3的pip安装模块,我是这做的,当然还有其他方法

进入python3的pip目录下cd C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\Scripts

执行命令 python3 -m pip install 包名

 验证import requests

 第二种方法:可以将路径添加到环境变量中C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\Scripts

然后直接执行python3 -m pip install requests,这种方法也是可以的

在安装一个django,支持python3的版本

 

 

 

 

 

 

3还有一个比较重要的,之前的代码在idle中,怎样选择是在python2还是python3环境中运行呢?

这里在打开的会后选择你要运行的环境就可以了

 

 同理,再sublime中可可以配置python2和python3的环境

在tool---build system--new build system中新建一个名字保存为python3

将下面粘贴进去

{

"cmd": ["自己的python3安装目录/python3.exe","-u","$file"],

"file_regex":"^[ ]*File \"(...*?)\", line ([0-9]*)",

"selector":"source.python",

"encoding": "utf-8" ,

"env": { "PYTHONIOENCODING": "utf8" },


}

重启sublime,然后选择python的build system 编写python文件,ctrl+b运行python文件就可以

 

=========================================================================================================

=========================================================================================================

如果python2和python3同事都安装了pytest,这时候想指定pytest的运行环境,该怎么处理

python3 pytest 会报错python3: can't open file 'pytest': [Errno 2] No such file or directory

解决方法:

python3 -m pytest

posted @ 2018-04-04 10:10  米 立  阅读(316)  评论(0编辑  收藏  举报