Windows 上的 Python 和 Virtualenv

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17737203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:02:53  来源:igfitidea点击:

Python and Virtualenv on Windows

pythonvirtualenv

提问by tambalolo

How do you install virtualenv correctly on windows?

你如何在windows上正确安装virtualenv?

I downloaded virtualenv1.9.1 from hereand tried installing it with:

我从这里下载了 virtualenv1.9.1并尝试安装它:

python virtualenv.py install

but it does not appear in MyPythonPath/Scripts

但它没有出现在 MyPythonPath/Scripts 中

I tried the same way installing virutalenvwrapper-winand it installed correctly. But I can't use it because I don't have virtualenv

我尝试以相同的方式安装virutalenvwrapper-win并且安装正确。但我不能使用它,因为我没有 virtualenv

python.exe: can't open file 'MyPythonPath\Scripts\virtualenv-script.py': [Errno 2 ] No such file or directory

python.exe: 无法打开文件 'MyPythonPath\Scripts\virtualenv-script.py': [Errno 2] 没有那个文件或目录

采纳答案by woozyking

The suggested way to install Python packages is to use pip

安装 Python 包的建议方法是使用 pip

Please follow this documentation to install pip: https://pip.pypa.io/en/latest/installing/

请按照此文档进行安装piphttps: //pip.pypa.io/en/latest/installing/

Note: Python 2.7.9 and above, and Python 3.4 and above include pip already.

注意:Python 2.7.9 及更高版本和 Python 3.4 及更高版本已经包含 pip。

Then install virtualenv:

然后安装virtualenv

pip install virtualenv

回答by Amit Verma

For installing virtualenv, you'll have to either install it using pip as mentioned in the answer by woozyking or you'll have to do something like this:

要安装 virtualenv,您必须使用 woozyking 的答案中提到的 pip 安装它,或者您必须执行以下操作:

$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz
$ tar xvfz virtualenv-1.9.1.tar.gz
$ cd virtualenv-1.9.1
$ [sudo] python setup.py install

The command which you have used can be used to create a virtualenv. I would recommend you go through these small videos on virtualenv and virtualenvwrapper to get a better understanding:

您使用的命令可用于创建 virtualenv。我建议你浏览这些关于 virtualenv 和 virtualenvwrapper 的小视频,以获得更好的理解:

python-power-tools-virtualenv

python-power-tools-virtualenv

virtualenvwrapper

虚拟包装器

回答by picibucor

There is an other way to install Python packages.

1: download the package, you want
2: open commander (press the win start-button and search for cmd)
3: cd into the folder where you downloaded your package
4: type: "python setup.py install"

还有另一种安装 Python 包的方法。

1:下载你想要的包
2:打开commander(按下win开始按钮并搜索cmd)
3:cd进入你下载包的文件夹
4:输入:“python setup.py install”

回答by Susa

Since I got the same error as mentioned in the question inspite of installing with:

由于我在安装时遇到了与问题中提到的相同的错误:

pip install virtualenv

I would like to add a few points, that might also help someone else solve the error in a similar way as me. Don't know if that's the best way, but for me nothing else helped.

我想补充几点,这也可能帮助其他人以与我类似的方式解决错误。不知道这是否是最好的方法,但对我来说没有其他帮助。

Install virtualenv

安装 virtualenv

pip install virtualenv

pip 安装 virtualenv

Move into Scripts directory

移动到脚本目录

cd C:\Python27\Scripts

Create a virtual env.

创建一个虚拟环境。

python virtualenv.exe my_env

Activate the virtual env.

激活虚拟环境。

my_env\Scripts\activate.bat

Deactivate the virtual env.

停用虚拟环境。

my_env\Scripts\deactivate.bat

回答by anubhab

  1. install virtualenv

    pip install virtualenv

  2. create a virtual environment

    python -m virtualenv demoEnv

  3. Activate the environment

    demoEnv\Scripts\activate

  4. To deactivate

    deactivate

  1. 安装虚拟环境

    pip 安装 virtualenv

  2. 创建虚拟环境

    python -m virtualenv demoEnv

  3. 激活环境

    演示环境\脚本\激活

  4. 停用

    停用