54

I'm a newbie to Python and I've spent hours on this. I can't seem to figure out why when I run a simple command to setup my Python environment: virtualenv --distribute env

This doesn't create a bin file in the env directory.

It only creates:

-- env
   -- Include
   -- Lib
   -- Scripts

My impressions was that a bin directory would be created per a lot of the examples I've found on the web (e.g. I'm not able to run this command: env/bin/activate).

I'm using Windows 7 and Python 2.7.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
avian
  • 1,693
  • 3
  • 20
  • 30

5 Answers5

97

On Windows, this is entirely correct. A bin directory is created on POSIX systems only. From the Windows Notes section of the documentation:

Some paths within the virtualenv are slightly different on Windows: scripts and executables on Windows go in ENV\Scripts\ instead of ENV/bin/ and libraries go in ENV\Lib\ rather than ENV/lib/.

For Windows, run \path\to\env\Scripts\activate to activate the virtualenv. From the documentation again:

On Windows you just do:

> \path\to\env\Scripts\activate

And type deactivate to undo the changes.

Based on your active shell (CMD.exe or Powershell.exe), Windows will use either activate.bat or activate.ps1 (as appropriate) to activate the virtual environment.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 1
    Wow... thansk for the super fast response. This has been driving me crazy. Makes it hard to follow examples on the web if this type of thing doesn't match. – avian Nov 03 '12 at 07:25
  • 2
    Most examples make the assumption you are using a POSIX (e.g. Linux or Mac) system. – Martijn Pieters Nov 03 '12 at 07:29
  • 1
    What about people using bash shells on windows? Eg Cygwin, MinGw, MySysGit, what are these folks to do? – ThorSummoner Apr 29 '14 at 04:32
  • 1
    As far as I understand--and I barely understand it--you need to execute the `activate.bat` file, *not* the `activate` file, which is in the same directory. – aliteralmind Jul 31 '14 at 15:16
  • @aliteralmind on windows the `.bat` extension is implied. No shell scripts are created on windows. E.g. When running `activate` the file with extension is found and exectuted, and there is no file by that name without an extension in the `Scripts` directory anyway. – Martijn Pieters Jul 31 '14 at 15:18
  • There is both an `activate` and `activate.bat` file in my `Scripts` directory. – aliteralmind Jul 31 '14 at 15:22
  • @aliteralmind: ah, yes, there is a shell file there too, for Cygwin, I see. But IIRC that file is ignored and the `.bat` is used. Then again, the docs I reference could predate the Cygwin support and that may no longer be true. – Martijn Pieters Jul 31 '14 at 15:38
  • @aliteralmind: the current documentation still states that `CMD.exe` will use `activate.bat` and Powershell will use `activate.ps1` when you do this. Is your experience different? – Martijn Pieters Jul 31 '14 at 15:40
  • Running `activate.bat` works. I was confused because I'm watching a Linux based tutorial, which tells you to execute `bin/activate`. If you look in the no-extension `activate` file, it says `# This file must be used with "source bin/activate" *from bash*`, `# you cannot run it directly`. I don't know how to do that. But the point's moot, as the bat file works. – aliteralmind Jul 31 '14 at 15:43
  • @aliteralmind: yes, but so will `Scripts\activate` as your console will then use `activate.bat`, *not* the shell script. – Martijn Pieters Jul 31 '14 at 15:44
  • Thanks for the information. Really nice and answer is to the point explains in details – Doogle Jan 01 '17 at 02:27
6

If you're using Git Bash for Windows, I found the following command works to activate the environment: $ source (path to environment)/Scripts/activate

I was using Git Bash on Windows 10, Python(v3.7), Pip (v19.0.3), virtualenv (v16.4.3)

zonian
  • 61
  • 1
  • 2
0

Yes, correct. On Windows, it creates the directory hierarchy as follows:

  • venv (virtual environment name)
    • Include
    • Lib\site-packages
    • Scripts

Just like in this image:

obnoxious screen shot.

tripleee
  • 175,061
  • 34
  • 275
  • 318
-1

For windows , you have to run python -m venv <your_env_name> and source <your_env_name>/Scripts/acivate. This works for me on windows.

i_priyanshu
  • 51
  • 1
  • 3
  • `source` is a Linux bash command. You might have used git bash on Windows at that moment, and then you should write this as well, and it would be a copy of another answer anyway. Downvote. – questionto42 Jun 26 '21 at 13:09
-1

If you're looking to point your IDE to the python.exe of your virtual env in Windows, its under the /scripts folder.