4

I'm trying to run an inherited Django project. I've set up a virtualenv and tried to pass in the requirements file via pip install -r requirements.txt. Everything seems to work. It tells me it's working in the correct virtualenv, and packages appear to install, e.g.:

Downloading/unpacking django-mediasync==2.2.0 (from -r requirements.txt (line 22))
  Downloading django-mediasync-2.2.0.tar.gz
  Running setup.py egg_info for package django-mediasync

But when I try to syncdb or runserver,

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10f15e290>>
Traceback (most recent call last):
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 88, in inner_run
    self.validate(display_num_errors=True)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/validation.py", line 36, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 76, in load_app
    app_module = import_module(app_name)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named mediasync

What's weird is that I install mediasync (or any other necessary packages) manually (pip install django-mediasync), the package can now be found.

What am I doing wrong? I don't want to have to install all of these packages manually.

AlexQueue
  • 6,353
  • 5
  • 35
  • 44
  • Are you sure, you were using `pip` from the same virtualenv? Check `which pip`. – alecxe Jul 22 '13 at 22:28
  • Yup. `/Users/me/.virtualenvs/example/bin/pip`. Also because when I instapp packages using pip "manually" rather than through the requirements.txt, they work out just fine. – AlexQueue Jul 22 '13 at 23:32
  • When you run `pip install django-mediasync`, what is the result? – Hieu Nguyen Jul 23 '13 at 00:08
  • @HieuNguyen It installs properly and is then found properly when I try to import it. I don't know why it works for that but not `pip install -r requirements.txt` (and yes I'll list django-mediasync in my requirements.txt file) – AlexQueue Jul 23 '13 at 01:37
  • there is an issue in the requirements.txt file then. Can you show its content? – François Constant Jul 23 '13 at 02:14
  • As mentioned in a comment below, check this out and see if it applies to your case: http://stackoverflow.com/a/11015904/439500 – hgcrpd Jul 25 '13 at 02:21

2 Answers2

3

I think when doing: pip install -r requirements.txt there was some error but you didn't notice. Basically the whole operation will stop at the time there is error.

So for example your requirements.txt have 4 packages like this:

A
B
C
D

If there is an error when installing B, 3 packages B, C and D will not be installed. It seems to me that there was an error with installation of one package in your requirements.txt and it didn't install django-mediasync at all.

If my hypothesis is right, please do pip install -r requirements.txt and check the last part of the traceback. If something fails, you will know exactly why.

Hieu Nguyen
  • 8,563
  • 2
  • 36
  • 43
  • 3
    I believe package A also won't be installed. My understanding was that pip would abort the whole command if one of the packages failed. – hgcrpd Jul 24 '13 at 01:58
  • I think `pip` uses serial operation so package A would be installed then. But yes I'm not so sure actually, and don't have time to make a test now. – Hieu Nguyen Jul 24 '13 at 11:15
  • Here we go, I found this one when scipy was giving me problems: http://stackoverflow.com/a/11015904/439500 – hgcrpd Jul 25 '13 at 02:20
  • The error message didn't really look like an error message so I took it that no error happened. – AlexQueue Jul 25 '13 at 19:16
  • My own experience agrees with @hgcrpd -- pip downloads and builds serially, but the actual installs don't happen until the end. So none of the packages get install if any error happens during the process. – Owen Feb 12 '14 at 17:53
1

Are you doing sudo pip install django-mediasync or sudo pip install -r requirements.txt? If so, it'll install it outside of the virtualenv. See How to install which programs requires "sudo" in virtualenv?.

Basically because your user should own the virtualenv directory, you don't need superuser privileges to install anything via pip. Do which pip and sudo which pip and you will see they are different.

The other possibility may be that your requirements.txt is not installing correctly. It may output lines like the line you mention, but apparently pip will scan all the packages in the requirements.txt before installing anything. If there is any error, it will abort the install for all packages.

Community
  • 1
  • 1
hgcrpd
  • 1,820
  • 3
  • 19
  • 32
  • I am not doing sudo for either. – AlexQueue Jul 23 '13 at 16:32
  • Ah. Thank you for clarifying the "all or nothing" nature of "pip install -r" ! Very educational. – starlocke Aug 12 '13 at 21:32
  • Actually, my experience contradicts the "all or nothing" theory. For whatever reason, a number of packages managed to get installed and some weren't installed. I managed to fix one line of my "requirements.txt" (added a specific version to one of the packages), which let pip go ahead and do a lot of installations. Once pip was done, "pip list" showed that the result was a partial installation. Mysterious! – starlocke Aug 12 '13 at 21:52