你如何在python 2和3之间切换,反之亦然?

时间:2021-08-10 10:20:05

I am reading How To Learn Python The Hard Way, which uses 2. Recently discovered Invent With Python, which uses 3.

我正在阅读如何学习Python的艰难之路,它使用2.最近发现的Invent With Python,它使用3。

Can I download python 3, and use it when I read Invent With Python, then switch back to python 2 when I want to read How To Learn Python The Hard Way. If so, how would I choose which version I use?

我可以下载python 3,并在阅读Invent With Python时使用它,然后当我想阅读如何学习Python的艰难之路时切换回python 2。如果是这样,我将如何选择使用哪个版本?

10 个解决方案

#1


23  

Using 'virtualenv' you can have different isolated Python environments on a single machine. Also you can switch any-time between the different python interpreter versions.

使用'virtualenv',您可以在一台机器上拥有不同的独立Python环境。您也可以在不同的python解释器版本之间切换任何时间。

What is virtualenv?

什么是virtualenv?

A Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. It enables multiple side-by-side installations of Python, one for each project. It doesn’t actually install separate copies of Python, but it does provide a clever way to keep different project environments isolated.

虚拟环境是Python的独立工作副本,它允许您处理特定项目而无需担心影响其他项目。它支持多个并行安装Python,每个项目一个。它实际上并没有安装Python的单独副本,但它确实提供了一种保持不同项目环境隔离的聪明方法。

How to install?

如何安装?

pip install virtualenv

To create virtual environment for python 2.7 :

为python 2.7创建虚拟环境:

root:~# which python2.7

/usr/bin/python2.7

root:~# which python3.4

/usr/local/bin/python3.4

You can also use a Python interpreter of your choice:

您还可以使用您选择的Python解释器:

root:~# virtualenv -p /usr/bin/python2.7 Vpy27

Running virtualenv with interpreter /usr/bin/python2.7

New python executable in /root/Vpy27/bin/python2.7

Also creating executable in /root/Vpy27/bin/python

Installing setuptools, pip, wheel...done.

To begin using the virtual environment, it needs to be activated:

要开始使用虚拟环境,需要激活它:

root:~# source Vpy27/bin/activate

The name of the current virtual environment will now appear on the left of the prompt:

现在,虚拟环境的名称将显示在提示的左侧:

(Vpy27) root:~# python -V
Python 2.7.3

Install packages as usual, for example:

像往常一样安装软件包,例如:

(Vpy27) root:~# pip install junos-eznc    >> All pip installs done here, will be available only in this environment.

If you are done working in the virtual environment for the moment, you can deactivate it:

如果您暂时在虚拟环境中工作,可以将其停用:

(Vpy27) root:~# deactivate   

To create virtual environment for python 3.4:

为python 3.4创建虚拟环境:

root:~# which python3.4

/usr/local/bin/python3.4

root:~# virtualenv -p /usr/local/bin/python3.4 Vpy34

root:~# source Vpy34/bin/activate

(Vpy34) root:~# python -V
Python 3.4.4

There is also a way to create virtual environment with already available site-packages.

还有一种方法可以使用已有的站点包创建虚拟环境。

#2


10  

depends on your system/platform...

取决于您的系统/平台......

I'm currently on Ubuntu 10.10 and have both 2.6 and 3.1 installed. The default system python is 2.6, and python3 is installed as an additional package.

我目前在Ubuntu 10.10上安装了2.6和3.1。默认系统python是2.6,python3作为附加包安装。

corey@studio17:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
corey@studio17:~$ python3
Python 3.1.2 (release31-maint, Sep 17 2010, 20:27:33) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

similarly, on Windows, I have 2.6 and 3.1 installed (in C:\Python26 and C:\Python31)

同样,在Windows上,我安装了2.6和3.1(在C:\ Python26和C:\ Python31中)

easy to switch back and forth.

容易来回切换。


also.. there are some syntactic differences between 2.x and 3.x that you will need to be aware of (print is a function, etc).

还有..你需要注意的是2.x和3.x之间存在一些语法差异(print是一个函数等)。

#3


3  

I'm on Windows 10 with Python 3.5 and 2.7. Using PowerShell, here's how I'm switching between versions.

我在使用Python 3.5和2.7的Windows 10上。使用PowerShell,这是我在不同版本之间切换的方式。

############################################################
# Switch to Python 2.7
############################################################

# Remove python 3.5 from PATH
$current_path = [Environment]::GetEnvironmentVariable("Path", "User")
$python3_path = "C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\;"
$new_path = $current_path.replace($python3_path, "")
[Environment]::SetEnvironmentVariable("Path", $new_path, "User")

# Add python 2.7 to PATH
# Run PowerShell as administrator
$current_path = [Environment]::GetEnvironmentVariable("Path", "Machine")
$python2_path = "C:\Python27\;C:\Python27\Scripts;"
$new_path = $python2_path + $current_path
[Environment]::SetEnvironmentVariable("Path", $new_path, "Machine")

# Restart PowerShell to see change

# Confirm change
python --version


############################################################
# Switch to Python 3.5
############################################################

# Remove python 2.7 from PATH
# Run PowerShell as administrator
$current_path = [Environment]::GetEnvironmentVariable("Path", "Machine")
$python2_path = "C:\Python27\;C:\Python27\Scripts;"
$new_path = $current_path.replace($python2_path, "")
[Environment]::SetEnvironmentVariable("Path", $new_path, "Machine")

# Add python 3.5 to PATH
$current_path = [Environment]::GetEnvironmentVariable("Path", "User")
$python3_path = "C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\;"
$new_path = $python3_path + $current_path
[Environment]::SetEnvironmentVariable("Path", $new_path, "User")

# Restart PowerShell to see change

# Confirm change
python --version

Note that you will need to update paths to reflect your Python versions and user profile.

请注意,您需要更新路径以反映您的Python版本和用户配置文件。

#4


1  

A couple ways on *nix systems:

在* nix系统上有几种方法:

  • Install into separate directories (e.g. /usr/local/python2 and /usr/local/python3) and create a link (e.g. /usr/bin/python) which you change to point to whichever executable you want to use.
  • 安装到单独的目录(例如/ usr / local / python2和/ usr / local / python3)并创建一个链接(例如/ usr / bin / python),您可以将其更改为指向要使用的任何可执行文件。

  • Same install as above, but set up separate python commands (e.g. /usr/bin/python2 and /usr/bin/python3) and call those when you want to invoke python. Or have the python command default to one of those and a pythonN for the other (N = 2 or 3, whichever isn't the default).
  • 与上面相同的安装,但设置单独的python命令(例如/ usr / bin / python2和/ usr / bin / python3)并在你想调用python时调用它们。或者让python命令默认为其中一个,另一个是pythonN(N = 2或3,取决于默认值)。

#5


1  

Yes you can. On my machine at least(Vista), v2 and v3 have completely separate idles allowing me to run whichever version I feel like when I feel like it. So go ahead and download v3.

是的你可以。至少在我的机器上(Vista),v2和v3有完全独立的空闲,允许我在我喜欢的时候运行我觉得的任何版本。所以继续下载v3。

#6


1  

In windows 10 it is a lot easier then what have been given by users above.

在Windows 10中,它比上面的用户给出的要容易得多。

Install both the version in separate folders, and then go to environment variable and add the path for both the versions.

将版本安装在单独的文件夹中,然后转到环境变量并为这两个版本添加路径。

Now any time you want to run particular version, just change its order (path) and move it to top of other version, and then restart the cmd and type python this time, you will see that only that particular version of python will run.

现在,只要你想运行特定版本,只需更改其顺序(路径)并将其移至其他版本的顶部,然后重新启动cmd并输入python这次,您将看到只有特定版本的python才会运行。

你如何在python 2和3之间切换,反之亦然?

For example in my case, I have two version of python one in anaconda(v3.0.6) and another is python 2.7

例如在我的情况下,我在anaconda(v3.0.6)中有两个版本的python,另一个是python 2.7

anytime I want to run the 2.7 i move its path above the anaconda version, as you can see in the screenshot above, and move it below when i want to run anaconda version.

任何时候我想运行2.7我将其路径移到anaconda版本上方,如上面的屏幕截图所示,当我想运行anaconda版本时将其移动到下方。

#7


0  

On Windows, the Python launcher can do this for you.

在Windows上,Python启动程序可以为您执行此操作。

The PEP article says:

PEP文章说:

Shebang line parsing

Shebang线解析

If the first command-line argument does not start with a dash ('-') character, an attempt will be made to open that argument as a file and parsed for a shebang line according to the rules in [1]::

如果第一个命令行参数不是以短划线(' - ')字符开头,则会尝试将该参数作为文件打开,并根据[1]中的规则解析为shebang行::

#! interpreter [optional-arg]

So simply add a shebang at the beginning of your Python script, like this:

所以只需在Python脚本的开头添加一个shebang,如下所示:

#! python3
#coding=utf-8

import sys
print(sys.version)
...

Or you can pass a command-line parameter to the py.exe launcher:

或者您可以将命令行参数传递给py.exe启动程序:

C:\Users\Administrator>py -3 my_script.py

C:\Users\Administrator>py -2 my_script.py

#8


0  

Here are my 2 cents.

这是我的2美分。

If you are on a unix based system (Ubuuntu, etc..), and you currently have python 2.x. Go ahead and download the python 3.x from Python.org

如果您使用的是基于unix的系统(Ubuuntu等),并且您目前拥有python 2.x.继续从Python.org下载python 3.x.

After installation it will create a separate directory python3

安装后,它将创建一个单独的目录python3

You are done.

你完成了。

To run your programs with python2.x use python filename.py

要使用python2.x运行程序,请使用python filename.py

To run your programs with python3.x, use python3 filename.py

要使用python3.x运行程序,请使用python3 filename.py

Similarly, to fire up the python2.x and python 3.x interpreter use python and python3 respectively.

同样,启动python2.x和python 3.x解释器分别使用python和python3。

I see some of the answers pointing you to virtualenv, I don't think that is what you were asking for, virtualenv is used for isolating Python environments.

我看到一些答案指向virtualenv,我不认为这是你要求的,virtualenv用于隔离Python环境。

#9


0  

if you are using windows 10 and have python 2.x and 3.x.

如果你使用的是Windows 10并且有python 2.x和3.x.

  1. open control panel > system and security > system
  2. 打开控制面板>系统和安全>系统

  3. click advanced system settings.
  4. 单击高级系统设置。

  5. click environment variables.
  6. 单击环境变量。

  7. click path and edit and then make the path of python version you want to use above that you don't want to use [by click the moveu Up button]
  8. 单击路径并编辑,然后在上面创建您不想使用的python版本的路径[通过单击moveu向上按钮]

  9. restart powershell.
  10. python --version

#10


0  

I've tried 6 solutions so far, like:

到目前为止,我已尝试过6种解决方案,例如:

virtualenv --python=python py27env
mkvirtualenv --python=python3 py3env etc..

also using virtualenvwrapper package etc. None of them worked.

也使用virtualenvwrapper包等。他们都没有工作。

I have Python 3.6 and Python2.7 on my Windows 10 machine, so I renamed C:\Python27\python.exe to python2.exe and C:\Python36\python.exe to python3.exe or you can even use python36.exe format. Of course C:\Python27, C:\Python27\Scripts, C:\Python36, C:\Python36\Scripts added to Environment Variables PATH.

我的Windows 10机器上有Python 3.6和Python2.7,因此我将C:\ Python27 \ python.exe重命名为python2.exe,将C:\ Python36 \ python.exe重命名为python3.exe,或者甚至可以使用python36.exe格式。当然C:\ Python27,C:\ Python27 \ Scripts,C:\ Python36,C:\ Python36 \ Scripts添加到Environment Variables PATH。

(1) For python3 just type:

(1)对于python3,只需输入:

python3 -m virtualenv venv3

python3 -m virtualenv venv3

(2) Go to venv folder, activate it with:

(2)转到venv文件夹,激活它:

Scripts\activate.bat

(3) (venv3) shows it's activated:

(3)(venv3)显示它被激活:

(venv3) HOME1@PC C:\Builts\venv3

(4) and then check if it is really 3.6:

(4)然后检查它是否真的是3.6:

python --version

Python 3.6.0

For python2:

python2 -m virtualenv venv2

python2 -m virtualenv venv2

Result:

(venv2) HOME1@PC C:\Builts\venv2
python --version
Python 2.7.9

I hope it will help.

我希望它会有所帮助。

#1


23  

Using 'virtualenv' you can have different isolated Python environments on a single machine. Also you can switch any-time between the different python interpreter versions.

使用'virtualenv',您可以在一台机器上拥有不同的独立Python环境。您也可以在不同的python解释器版本之间切换任何时间。

What is virtualenv?

什么是virtualenv?

A Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. It enables multiple side-by-side installations of Python, one for each project. It doesn’t actually install separate copies of Python, but it does provide a clever way to keep different project environments isolated.

虚拟环境是Python的独立工作副本,它允许您处理特定项目而无需担心影响其他项目。它支持多个并行安装Python,每个项目一个。它实际上并没有安装Python的单独副本,但它确实提供了一种保持不同项目环境隔离的聪明方法。

How to install?

如何安装?

pip install virtualenv

To create virtual environment for python 2.7 :

为python 2.7创建虚拟环境:

root:~# which python2.7

/usr/bin/python2.7

root:~# which python3.4

/usr/local/bin/python3.4

You can also use a Python interpreter of your choice:

您还可以使用您选择的Python解释器:

root:~# virtualenv -p /usr/bin/python2.7 Vpy27

Running virtualenv with interpreter /usr/bin/python2.7

New python executable in /root/Vpy27/bin/python2.7

Also creating executable in /root/Vpy27/bin/python

Installing setuptools, pip, wheel...done.

To begin using the virtual environment, it needs to be activated:

要开始使用虚拟环境,需要激活它:

root:~# source Vpy27/bin/activate

The name of the current virtual environment will now appear on the left of the prompt:

现在,虚拟环境的名称将显示在提示的左侧:

(Vpy27) root:~# python -V
Python 2.7.3

Install packages as usual, for example:

像往常一样安装软件包,例如:

(Vpy27) root:~# pip install junos-eznc    >> All pip installs done here, will be available only in this environment.

If you are done working in the virtual environment for the moment, you can deactivate it:

如果您暂时在虚拟环境中工作,可以将其停用:

(Vpy27) root:~# deactivate   

To create virtual environment for python 3.4:

为python 3.4创建虚拟环境:

root:~# which python3.4

/usr/local/bin/python3.4

root:~# virtualenv -p /usr/local/bin/python3.4 Vpy34

root:~# source Vpy34/bin/activate

(Vpy34) root:~# python -V
Python 3.4.4

There is also a way to create virtual environment with already available site-packages.

还有一种方法可以使用已有的站点包创建虚拟环境。

#2


10  

depends on your system/platform...

取决于您的系统/平台......

I'm currently on Ubuntu 10.10 and have both 2.6 and 3.1 installed. The default system python is 2.6, and python3 is installed as an additional package.

我目前在Ubuntu 10.10上安装了2.6和3.1。默认系统python是2.6,python3作为附加包安装。

corey@studio17:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
corey@studio17:~$ python3
Python 3.1.2 (release31-maint, Sep 17 2010, 20:27:33) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

similarly, on Windows, I have 2.6 and 3.1 installed (in C:\Python26 and C:\Python31)

同样,在Windows上,我安装了2.6和3.1(在C:\ Python26和C:\ Python31中)

easy to switch back and forth.

容易来回切换。


also.. there are some syntactic differences between 2.x and 3.x that you will need to be aware of (print is a function, etc).

还有..你需要注意的是2.x和3.x之间存在一些语法差异(print是一个函数等)。

#3


3  

I'm on Windows 10 with Python 3.5 and 2.7. Using PowerShell, here's how I'm switching between versions.

我在使用Python 3.5和2.7的Windows 10上。使用PowerShell,这是我在不同版本之间切换的方式。

############################################################
# Switch to Python 2.7
############################################################

# Remove python 3.5 from PATH
$current_path = [Environment]::GetEnvironmentVariable("Path", "User")
$python3_path = "C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\;"
$new_path = $current_path.replace($python3_path, "")
[Environment]::SetEnvironmentVariable("Path", $new_path, "User")

# Add python 2.7 to PATH
# Run PowerShell as administrator
$current_path = [Environment]::GetEnvironmentVariable("Path", "Machine")
$python2_path = "C:\Python27\;C:\Python27\Scripts;"
$new_path = $python2_path + $current_path
[Environment]::SetEnvironmentVariable("Path", $new_path, "Machine")

# Restart PowerShell to see change

# Confirm change
python --version


############################################################
# Switch to Python 3.5
############################################################

# Remove python 2.7 from PATH
# Run PowerShell as administrator
$current_path = [Environment]::GetEnvironmentVariable("Path", "Machine")
$python2_path = "C:\Python27\;C:\Python27\Scripts;"
$new_path = $current_path.replace($python2_path, "")
[Environment]::SetEnvironmentVariable("Path", $new_path, "Machine")

# Add python 3.5 to PATH
$current_path = [Environment]::GetEnvironmentVariable("Path", "User")
$python3_path = "C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\REPLACEUSER\AppData\Local\Programs\Python\Python35-32\;"
$new_path = $python3_path + $current_path
[Environment]::SetEnvironmentVariable("Path", $new_path, "User")

# Restart PowerShell to see change

# Confirm change
python --version

Note that you will need to update paths to reflect your Python versions and user profile.

请注意,您需要更新路径以反映您的Python版本和用户配置文件。

#4


1  

A couple ways on *nix systems:

在* nix系统上有几种方法:

  • Install into separate directories (e.g. /usr/local/python2 and /usr/local/python3) and create a link (e.g. /usr/bin/python) which you change to point to whichever executable you want to use.
  • 安装到单独的目录(例如/ usr / local / python2和/ usr / local / python3)并创建一个链接(例如/ usr / bin / python),您可以将其更改为指向要使用的任何可执行文件。

  • Same install as above, but set up separate python commands (e.g. /usr/bin/python2 and /usr/bin/python3) and call those when you want to invoke python. Or have the python command default to one of those and a pythonN for the other (N = 2 or 3, whichever isn't the default).
  • 与上面相同的安装,但设置单独的python命令(例如/ usr / bin / python2和/ usr / bin / python3)并在你想调用python时调用它们。或者让python命令默认为其中一个,另一个是pythonN(N = 2或3,取决于默认值)。

#5


1  

Yes you can. On my machine at least(Vista), v2 and v3 have completely separate idles allowing me to run whichever version I feel like when I feel like it. So go ahead and download v3.

是的你可以。至少在我的机器上(Vista),v2和v3有完全独立的空闲,允许我在我喜欢的时候运行我觉得的任何版本。所以继续下载v3。

#6


1  

In windows 10 it is a lot easier then what have been given by users above.

在Windows 10中,它比上面的用户给出的要容易得多。

Install both the version in separate folders, and then go to environment variable and add the path for both the versions.

将版本安装在单独的文件夹中,然后转到环境变量并为这两个版本添加路径。

Now any time you want to run particular version, just change its order (path) and move it to top of other version, and then restart the cmd and type python this time, you will see that only that particular version of python will run.

现在,只要你想运行特定版本,只需更改其顺序(路径)并将其移至其他版本的顶部,然后重新启动cmd并输入python这次,您将看到只有特定版本的python才会运行。

你如何在python 2和3之间切换,反之亦然?

For example in my case, I have two version of python one in anaconda(v3.0.6) and another is python 2.7

例如在我的情况下,我在anaconda(v3.0.6)中有两个版本的python,另一个是python 2.7

anytime I want to run the 2.7 i move its path above the anaconda version, as you can see in the screenshot above, and move it below when i want to run anaconda version.

任何时候我想运行2.7我将其路径移到anaconda版本上方,如上面的屏幕截图所示,当我想运行anaconda版本时将其移动到下方。

#7


0  

On Windows, the Python launcher can do this for you.

在Windows上,Python启动程序可以为您执行此操作。

The PEP article says:

PEP文章说:

Shebang line parsing

Shebang线解析

If the first command-line argument does not start with a dash ('-') character, an attempt will be made to open that argument as a file and parsed for a shebang line according to the rules in [1]::

如果第一个命令行参数不是以短划线(' - ')字符开头,则会尝试将该参数作为文件打开,并根据[1]中的规则解析为shebang行::

#! interpreter [optional-arg]

So simply add a shebang at the beginning of your Python script, like this:

所以只需在Python脚本的开头添加一个shebang,如下所示:

#! python3
#coding=utf-8

import sys
print(sys.version)
...

Or you can pass a command-line parameter to the py.exe launcher:

或者您可以将命令行参数传递给py.exe启动程序:

C:\Users\Administrator>py -3 my_script.py

C:\Users\Administrator>py -2 my_script.py

#8


0  

Here are my 2 cents.

这是我的2美分。

If you are on a unix based system (Ubuuntu, etc..), and you currently have python 2.x. Go ahead and download the python 3.x from Python.org

如果您使用的是基于unix的系统(Ubuuntu等),并且您目前拥有python 2.x.继续从Python.org下载python 3.x.

After installation it will create a separate directory python3

安装后,它将创建一个单独的目录python3

You are done.

你完成了。

To run your programs with python2.x use python filename.py

要使用python2.x运行程序,请使用python filename.py

To run your programs with python3.x, use python3 filename.py

要使用python3.x运行程序,请使用python3 filename.py

Similarly, to fire up the python2.x and python 3.x interpreter use python and python3 respectively.

同样,启动python2.x和python 3.x解释器分别使用python和python3。

I see some of the answers pointing you to virtualenv, I don't think that is what you were asking for, virtualenv is used for isolating Python environments.

我看到一些答案指向virtualenv,我不认为这是你要求的,virtualenv用于隔离Python环境。

#9


0  

if you are using windows 10 and have python 2.x and 3.x.

如果你使用的是Windows 10并且有python 2.x和3.x.

  1. open control panel > system and security > system
  2. 打开控制面板>系统和安全>系统

  3. click advanced system settings.
  4. 单击高级系统设置。

  5. click environment variables.
  6. 单击环境变量。

  7. click path and edit and then make the path of python version you want to use above that you don't want to use [by click the moveu Up button]
  8. 单击路径并编辑,然后在上面创建您不想使用的python版本的路径[通过单击moveu向上按钮]

  9. restart powershell.
  10. python --version

#10


0  

I've tried 6 solutions so far, like:

到目前为止,我已尝试过6种解决方案,例如:

virtualenv --python=python py27env
mkvirtualenv --python=python3 py3env etc..

also using virtualenvwrapper package etc. None of them worked.

也使用virtualenvwrapper包等。他们都没有工作。

I have Python 3.6 and Python2.7 on my Windows 10 machine, so I renamed C:\Python27\python.exe to python2.exe and C:\Python36\python.exe to python3.exe or you can even use python36.exe format. Of course C:\Python27, C:\Python27\Scripts, C:\Python36, C:\Python36\Scripts added to Environment Variables PATH.

我的Windows 10机器上有Python 3.6和Python2.7,因此我将C:\ Python27 \ python.exe重命名为python2.exe,将C:\ Python36 \ python.exe重命名为python3.exe,或者甚至可以使用python36.exe格式。当然C:\ Python27,C:\ Python27 \ Scripts,C:\ Python36,C:\ Python36 \ Scripts添加到Environment Variables PATH。

(1) For python3 just type:

(1)对于python3,只需输入:

python3 -m virtualenv venv3

python3 -m virtualenv venv3

(2) Go to venv folder, activate it with:

(2)转到venv文件夹,激活它:

Scripts\activate.bat

(3) (venv3) shows it's activated:

(3)(venv3)显示它被激活:

(venv3) HOME1@PC C:\Builts\venv3

(4) and then check if it is really 3.6:

(4)然后检查它是否真的是3.6:

python --version

Python 3.6.0

For python2:

python2 -m virtualenv venv2

python2 -m virtualenv venv2

Result:

(venv2) HOME1@PC C:\Builts\venv2
python --version
Python 2.7.9

I hope it will help.

我希望它会有所帮助。