1

I've installed django and python as this link suggested with macports. However, I'd like to use virtualenv to install more packages. My understanding is that if I do not pass in the --no-site-packages to virtualenv, I should get the currently installed packages in addition to whatever packages I install into the virtual environment. Is this correct?

As an example, I've installed django through macports and then create a virtual environment, but I cannot import django from within that virtual environment:

[streeter@mordecai]:~$ mkvirtualenv django-test
New python executable in django-test/bin/python
Installing setuptools............done.
...
(django-test)[streeter@mordecai]:~$ pip install django-debug-toolbar
Downloading/unpacking django-debug-toolbar
  Downloading django-debug-toolbar-0.8.4.tar.gz (80Kb): 80Kb downloaded
  Running setup.py egg_info for package django-debug-toolbar
Installing collected packages: django-debug-toolbar
  Running setup.py install for django-debug-toolbar
Successfully installed django-debug-toolbar
Cleaning up...
(django-test)[streeter@mordecai]:~$ python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
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
>>>

So I can install packages into the virtual environment, but it isn't picking up the global site-packages. Or am I not doing something correctly / missing something / misunderstanding how virtualenv works?

I've got Mac OS 10.6 (Snow Leopard), have updated my macports packages and am using macports' python26 (via python_select python26).

Edit:

Also I've checked that my macports PATH is setup correctly. Here's some output:

[streeter@mordecai]:~$ python --version
Python 2.6.6
[streeter@mordecai]:~$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Users/streeter/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/streeter/.ec2/bin
[streeter@mordecai]:~$ source dev/python-environments/test/bin/activate
(test)[streeter@mordecai]:~$ python --version
Python 2.6.1
(test)[streeter@mordecai]:~$ 

virtualenv and virtualenvwrapper were both installed using pip, not using macports as that didn't seem to create a file to source at /usr/local/bin/virtualenvwrapper.sh, so I'm not sure how to get the aliases for virtualenvwrapper.

Community
  • 1
  • 1
Streeter
  • 556
  • 4
  • 22

1 Answers1

1

You are not using the MacPorts Python as evidenced by the version and date displayed. (Try typing /usr/bin/python2.6 and then /opt/local/bin/python2.6.) Just setting MacPorts python_select does no good if you do not put the MacPorts bin directory first on your shell execution PATH:

$ export PATH=/opt/local/bin:$PATH

You may need to recreate the virtualenv making sure you are using the MacPorts Python instead of the Apple-supplied Python.

EDIT: With the additional information, I would guess that your $PATH was not set properly prior to initially sourcing virtualwrapper.sh as described here. I suggest you go back and follow the instructions there, making sure you have really installed virtualenv and virtualenvwrapper to the MacPorts site-packages directory, and not the system Python's. Note, the version of virtualenvwrapper currently available through MacPorts for Python 2.6 is an older one, 1.20; the shell script for it has a different name.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151