2

I'm relatively new to running Python with virtualenv so this might be an easy fix, but I can't for the life of me figure out what's going on. I'm running Windows 7 professional x64 with Python 2.7.5 installed I have installed pip and virtualenv. I have a django project that I'm attempting to work on which I have cloned from a Heroku repository. When I attempt to set up a virtualenv and install the requirements of my project I'm running into a strange error that I can't figure out. I have everything setup as follows:

Django project is placed in C:\Users\xxx\PythonProjects\myProject

I open a command prompt, cd to the myProject folder and execute the following command:

C:\Users\xxx\PythonProjects\myProject> virtualenv --no-site-packages env

This should create a nice clean virtual environment for my project, so I go ahead and activate as follows:

C:\Users\xxx\PythonProjects\myProject> Scripts\activate

The prompt changes to indicate my virtualenv has become active so I double check by "where"ing python and pip:

(env) C:\Users\xxx\PythonProjects\myProject> where python
C:\Users\xxx\PythonProjects\myProject\env\Scripts\python.exe
C:\Python27\python.exe

(env) C:\Users\xxx\PythonProjects\myProject>where pip
C:\Users\xxx\PythonProjects\myProject\env\Scripts\pip.exe
C:\Python27\Scripts\pip.exe

Since it looks like virtualenv is functioning correctly I next attempt to pip the requirements file as follows:

(env) C:\Users\xxx\PythonProjects\myProject> pip install -r requirements.txt

pip appears to run successfully installing all the packages I need. However when I load up python the following happens (django is one of the packages in my requirements file):

(env) C:\Users\xxx\PythonProjects\myProject>python
Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django

I then cd to the site-packages folder to find out what is going on and get the following:

(env) C:\Users\xxx\PythonProjects\myProject\Lib\site-packages>dir
 Volume in drive C is Windows7_OS
 Volume Serial Number is 808F-577A

 Directory of C:\Users\xxx\PythonProjects\myProject\env\Lib\site-packages

07/17/2013  02:16 PM    <DIR>          .
07/17/2013  02:16 PM    <DIR>          ..
07/17/2013  02:16 PM               237 easy-install.pth
07/17/2013  02:16 PM    <DIR>          pip-1.3.1-py2.7.egg
07/15/2013  09:16 PM           332,005 setuptools-0.6c11-py2.7.egg
07/17/2013  02:16 PM                31 setuptools.pth
               3 File(s)        332,273 bytes
               3 Dir(s)  169,869,336,576 bytes free

It appears that my pip call failed to install ANYTHING into my site-packages folder, so python has no idea where to find my required packages. Instead they appear to all be located in C:\Users\xxx\PythonProjects\myProject\env\build

If I use pip install foo without a requirements file, then everything works fine and the foo ends up in my site-packages folder. Is there a way I can get this working with the requirements file, or am I going to have to manually install every package every time when using virtualenv? Sorry for the likely overly long post, but I wanted to make sure that all relevant information is here. Thanks for the help!


Edit with additional information:

It appears that my requirements file may be the source of the problem. Only about half of the packages are being downloaded, the last being django-polymorphic. The lines in my requirements file that specify that package and the following package are as follows:

django-polymorphic==0.4.2
-e hg+https://bitbucket.org/fcurella/django-profiles@5c982ce7c040351fca9847a85dd4ff29f8a367e6#egg=django_profiles-dev
django-sekizai==0.7
-e git://github.com/divio/django-shop.git@0fb2258d27332166e3f76ad7cf7335c1f0a389b2#egg=django_shop-dev
-e git://github.com/fivethreeo/django-shop-categories.git@345fb100f5f680e6ac2066f74f25515eb2cd9374#egg=django_shop_categories-dev`
JoeliusCaeser
  • 85
  • 2
  • 8
  • To be clear, I have tried this set up both with and without the `--no-site-packages` flag. The results are the same every time. – JoeliusCaeser Jul 17 '13 at 20:01
  • I don't have `virtualenv` under windows setup. However if I remember correctly, the packages installed through `pip` would settle in `dist-packages`. Would you check that and add the result to your question description? Thank you :) – woozyking Jul 17 '13 at 20:03
  • Thanks for the quick response. There doesn't appear to be a `dist-packages` folder anywhere in the env subdirectories. I'm assuming that it would be located at `myProject\env\Lib\dist-packages` if it did exist? – JoeliusCaeser Jul 17 '13 at 20:07
  • Never mind. Hmm, it looks like virtualenv under Windows does have a different behavior. However I do have Django successfully installed in the virtualenv and the lib files are indeed under `Lib\site-packages`. I'm using PowerShell, FYI. – woozyking Jul 17 '13 at 20:12
  • Let's try to diagnose with the following steps. 1) wipe clean and rebuild a virtualenv 2) activate the newly built virtualenv 3) Perform `pip freeze` and note the listed packages 4) Perform `pip install -U distribute setuptools` 5) Perform `pip freeze` and note the difference compare to step 3's result. – woozyking Jul 17 '13 at 20:21
  • 1
    Following the activation of the new `virtualenv`, `pip freeze` returns nothing. Following `pip install -U distribute setuptools` I have `pip freeze` returning `distribute==0.7.3` – JoeliusCaeser Jul 17 '13 at 21:47
  • I guess there's an error when installing one of packages listed in `requirements.txt` which stops the whole installation. Check out pip log to see what happened. – Piotr Dobrogost Jul 18 '13 at 10:39
  • @PiotrDobrogost I think you're right. I did a closer comparison, and it looks like the `build` folder only has about half of the packages from my `requirements.txt` file (I can't find a pip log file). – JoeliusCaeser Jul 18 '13 at 16:52
  • I edited the post to reflect the additional information that I could find. – JoeliusCaeser Jul 18 '13 at 16:58
  • I have no problem with installation using requirements file from your question. – Piotr Dobrogost Jul 18 '13 at 22:22

1 Answers1

1

So I figured out the answer to my own question.

Basically, if you are running Python 2.7 (and likely other versions) on Windows, some packages don't play nicely. If anyone else is having this problem, you should download Windows binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and remove those packages from your requirements.txt file. Once I did so, pip stopped crashing during the install process and correctly installed the rest of the packages in my requirements.txt file.

The packages I needed were:

  1. pillow
  2. psycopg
  3. reportlab
JoeliusCaeser
  • 85
  • 2
  • 8
  • Note: the Windows binaries by default will install to the global `site-packages` folder. This means that when you set up your virtual environment you're going to have to use the `--system-site-packages` flag. If you've already set up a virtual environment with `--no-site-packages` you can disable that behavior by renaming the `/Lib/no-global-site-packages.txt` file (or deleting it entirely). I assume you could also copy the contents of the global `site-packages` folder into your virtual environment's `site-packages`, but I haven't messed around with that yet. Things are working... – JoeliusCaeser Jul 19 '13 at 01:58
  • *(...) some packages don't play nicely* They play by the rules. You have to know these rules. *you're going to have to use the `--system-site-packages`* Not only you don't have to but you should not set this flag - see [Can I install Python windows packages into virtualenvs?](http://stackoverflow.com/q/3271590/95735) – Piotr Dobrogost Jul 19 '13 at 18:19
  • I was merely observing that the set of instructions I left only worked for me with the `--system-site-packages` flag. As I said, I hadn't messed with moving those packages into the local virtualenv (as I'm only running one project at the moment, it wasn't a pressing issue). – JoeliusCaeser Jul 19 '13 at 19:10