26

How do you install virtualenv correctly on windows?

I downloaded virtualenv1.9.1 from here and tried installing it with:

python virtualenv.py install

but it does not appear in MyPythonPath/Scripts

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

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

tambalolo
  • 1,035
  • 3
  • 14
  • 30
  • For Python v3 you probably want `pyvenv` which can be found from this SO question: http://stackoverflow.com/questions/15981111/where-is-pyvenv-script-in-python-3-on-windows-installed – icc97 Mar 27 '16 at 00:24

6 Answers6

25

The suggested way to install Python packages is to use pip

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

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

Then install virtualenv:

pip install virtualenv
Makoto
  • 104,088
  • 27
  • 192
  • 230
woozyking
  • 4,880
  • 1
  • 23
  • 29
  • You're welcome. A suggestion about filtering learning resources: always go for language official documentations first, then maybe SO and/or Google :) – woozyking Jul 19 '13 at 04:50
  • I installed stuff with pip and still have the missing virtualenv-script.py error, but I'm attempting to install on powershell which may be complicating things. – rschwieb Nov 18 '14 at 18:03
  • @rschwieb installing it on powershell should be fine. Checkout http://virtualenv.readthedocs.org/en/latest/virtualenv.html#activate-script for details under Windows environments. – woozyking Nov 18 '14 at 19:50
  • PermissionError. My python installation is in program files. Workaround? – Santosh Kumar Jul 14 '17 at 08:59
12

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

pip install 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
Vallie
  • 689
  • 9
  • 19
Susa
  • 361
  • 4
  • 9
4
  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

anubhab
  • 730
  • 1
  • 7
  • 11
3

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"

picibucor
  • 753
  • 1
  • 8
  • 25
2

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:

$ 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:

python-power-tools-virtualenv

virtualenvwrapper

Amit
  • 19,780
  • 6
  • 46
  • 54
2

Creating a Virtual Environment on Windows


1. Create a virtual environment

python -m venv myenv

2. Activate

.\myenv\Scripts\activate

3. Extra information

  • To disable write
    • deactivate
  • These commands will also work on windows
    • myenv\Scripts\activate
    • myenv\Scripts\activate.bat
    • .\myenv\Scripts\activate.bat
  • Be careful with slashes:
    • myenv/Scripts/activate.bat
  • I prefer using this naming:
    • python -m venv .venv
    • .venv\Scripts\activate

4. Screenshot

enter image description here

5. Sources

Hasan Gökçe
  • 501
  • 6
  • 6