dyld: Library not loaded: @executable_path/../.Python

2011.11.13 | Python | , ,


Problem:

You’re trying to use a virtual environment created on a different computer, or you’ve upgraded / reformated your machine and you’re using the virtenv from your backup of the old machine.

Now you try to do a pip install but you get the following error:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /your/project/path/./bin/python
  Reason: image not found

Solution:

The python executable or libraries in the virtualenv directory are not compatible with your current architecture. This happened to me when I reformatted my Macbook to run OS X 10.7 Lion from an older version of OS X.

To fix, you’ll need to create a new virtual env. What you can do is freeze the packages the current virtualenv is using (if you’re not doing this already), and then install them in the new virtual environment.

pip freeze -E your_old_environment > requirements.txt
pip install -E your_new_environment -r requirements.txt

Now use your new virtual env as you did your old one. it’s also good practice to keep a file with the latest contents of pip freeze in your code repository, in case you need to build new virtualenvs in the future (or deploy them).

  • Doug Duran

    exactly what i was looking for, thanks!

  • Tom Elliott

    no such option: -E

    • http://zaahir.ca/ Zaahir Moolla

      I had the same problem, but I’m not entirely sure the -E is necessary anyways. Simply freezing the requirements into my requirements.txt and reinstalling them from that file worked for me