Search code examples
pythondjangovirtualenveasy-install

Installing django with easy_install in a virtualenv


I'm new to virtualenv, so perhaps I'm simply overlooking something. I have successfully set up a virtual environment. I have run activate.bat, which is evident in the command window and when I check PATH environment variable.

I'm running 64-bit Python 2.7.8 on Windows in my virtual environment. Following the activation of the virtualenv, I execute easy_install django, which installs django, but installs it globally and not to the isolated environment. I confirmed this by firing up the interpreter and typing import django...resulting in an import error.

Without skipping a beat, I tried pip install django from the same activated command prompt, and it worked like a charm.

So...with easy_install...what gives? Is this an easy_install error or a virtualenv error? Unfortunately, since the django install via easy_install didn't fail to install (it installed globally), I have no helpful error messages to provide.


Solution

  • I never use the activate.bat script. I just end up with problems if I do (edit - after looking into it a little, I suspect it is a legacy script for people using old MS-DOS prompts). Use the activate.ps1 script.

    ...\virtualenv_name\Scripts\activate.ps1

    You may have to change permissions (see the execution policy section in the guide). As I understand it, the RemoteSigned policy is preferred over Unrestricted.

    You should get a prefix on your command prompt with the name of your virtualenv. Something like (virtualenv_name) PC C:\> Now pip should work:

    pip install django

    You can use easy_install but ... don't since pip is the standard. Unless you have a special case where it works and pip doesn't.