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


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


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).