Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

A while ago I had both Python 2.7 and 3.5 installed on my Mac and was able to use them both successfully. Not too long ago, I installed Anaconda and IPython. I have used those for a couple weeks for prototyping and in-console programming.

After I went back to the regular Python for my Django and Flask projects, I discovered an unpleasant thing. Namely, whenever I try to run python or python3 I get the following error:

dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/name/anaconda3/bin/python3
  Reason: image not found
Abort trap: 6

When I run conda I also get the same error.

If I create a new virtual environment with virtualenv django-project, I am able to activate it, and it allows me to run Python 2.7 successfully.

My question is the following: How can I fix python and python3 for the command line while also retaining the working Anaconda and IPython? How can I make sure that the virtual environments are able to carry Python 3?

like image 686
MadPhysicist Avatar asked Mar 10 '17 03:03

MadPhysicist


1 Answers

I also use macOS and I never mess with or even deal with the system python. I've installed python3 via Homebrew (https://brew.sh) and I always use a virtual environment. I have one in my home directory (my default) and I have one for each project I'm working on.

Your rule of thumb should be to never run 'pip' if you aren't within a virtualenv. Check with $ echo $VIRTUAL_ENV.

To create/recreate the virtual environment in python3 with the currently installed libraries:

  • Get into your project directory and active your virtualenv.
  • (optional) Dump your requirements via pip: $ pip freeze > requirements.txt
  • Nuke your virtual environment directory if you have one: $ rm -rf .venv
  • Deactivate it: $ deactivate
  • Create a new one with python3: $ virtualenv -p python3 .venv
  • Activate it: $ source .venv/bin/activate
  • (optional) Install your requirements: $ pip install -r requirements.txt
  • Profit.

You can skip the steps for writing and reading the requirements.txt if you just want to create a new virtual environment and then install only the modules you want/need later.

like image 136
TheZeke Avatar answered Sep 25 '22 04:09

TheZeke