1

I have been using the standard python that comes with OS X Lion (2.7.2) but I wanted to build a UCS-4 version to handle 4-byte unicode characters better.

I had already installed pip and packages like pytz, virtualenv and virtualenvwrapper, etc., and these are installed in /Library/Python/2.7/site-packages. My $PATH is /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.

To build a new version of python on the machine (outside of any project specific virtual environments, that will come later), I followed the instructions on this article and managed to build it in /usr/local/bin. The problem is that when I launched a new bash window, I got the following virtualenvwrapper error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named virtualenvwrapper.hook_loader virtualenvwrapper.sh: There was a problem running the initialization hooks. 

If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is set properly.

The instructions said to move /usr/local/bin to the top of the /etc/paths file, and since then I've noticed some strange issues. I installed pip into /usr/local/bin and now I have assumed that since I'm working in /usr/local/bin, and the newly installed python's site packages is now located in /usr/local/lib/python2.7/site-packages, when I do pip freeze, it should be empty as nothing is installed there yet. However, pip freeze still reports things installed in the old (OS X) site-packages folder. Here's some info after the build:

$ which python
/usr/local/bin/python
$ which pip
/usr/local/bin/pip
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

When I uninstall a python package with pip, it removes it from the old site-packages folder as expected. When I install it again, instead of installing it in /usr/local/lib/python2.7/site-packages, it installs it in /Library/Python/2.7/site-packages (verified by attempting to install it again and receiving Requirement already satisfied (use --upgrade to upgrade): pytz in /Library/Python/2.7/site-packages ). How is it getting that path for the old site-packages folder? Why won't it install it in the correct location for the python install it's using?

I'm getting several other issues since promoting /usr/local/bin but I think if I understand this I'll be able to get somewhere.

Can anyone see what's happening? If you need any more info I'll be happy to provide it.

Michael Waterfall
  • 20,497
  • 27
  • 111
  • 168
  • What does the first line of /usr/local/bin/pip point to, your custom python installation or the system one? – kristaps Sep 07 '12 at 19:04
  • Ahhh... the shebang is `#!/usr/bin/python`. That explains a lot! How could that have gotten into the `/usr/local/bin` version of `pip`?? – Michael Waterfall Sep 07 '12 at 19:27
  • @kristaps: I've noticed that lots of things in `/usr/local/bin` (for example pip, easy_install, django-admin.py) all have `#!/usr/bin/python` as the shebang. Do you know why that could be? – Michael Waterfall Sep 07 '12 at 19:38
  • /usr/local/bin is the traditional place to put binaries that didn't come with OS, so easy_install/pip putting packaged binaries there is quite reasonable. – kristaps Sep 07 '12 at 20:14

1 Answers1

1

Since you will be using the custom python installation as your main one, I suggest you uninstall all non-standard packages from the system python and make sure that the existing easy_install.py is gone (possibly by manually removing it). Then download distribute's distribute_setup.py and run it with the new interpreter. From then on everything should work as expected.

kristaps
  • 1,705
  • 11
  • 15
  • Yes, this is what I've ended up doing. I used pythonbrew and then followed the [info here](http://stackoverflow.com/q/4324558/106244) to install things again properly. – Michael Waterfall Sep 09 '12 at 12:49