Python 2和Python 3混合错误与虚拟环境?

时间:2017-02-26 02:13:54

标签: python python-2.7 python-3.x virtualenv

1)我用安装程序在Windows上安装了python3.5。我检查了设置路径。

2)我用安装程序在Windows上安装了python2.7。我检查了设置路径。

  • python 3位于C:\ Users \ amand \ AppData \ Local \ Programs \ Python \ Python35-32
  • python 2在C:\ Python27
  • 中找到

3)我打开命令提示符

>>> python -m venv tutorial-env
C:\Python27\python.exe: No module named venv

好的......那么......

>>>py -3
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit      
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>>python -m venv tutorial-env
>File "<stdin>", line 1
python -m venv tutorial-env
             ^
SyntaxError: invalid syntax

好。我关闭了命令提示符并启动了一个新命令。该文件说使用这个......但是......

>>>>python3 -m venv tutorial-env
'python3' is not recognized as an internal or external command,
operable program or batch file.

我所指的文档 https://docs.python.org/3/tutorial/venv.html

1 个答案:

答案 0 :(得分:0)

使用特定的python:

python3 -m venv tutorial-env #for python 3
python2 -m venv tutorial-env #for python 2
#if you have multple versions of 3 or 2
python2.7 -m venv tutorial-env #for python 2.7
python3.5 -m venv tutorial-env #for python 3.5 or something along the lines

修改

如果在Windows及以上版本中无效:

#In command prompt
py -3 #or -2
>>> import venv
>>> venv.main('tutorial-env')

py -3 -m venv tutorial-env