简体   繁体   中英

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?

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.

firstly, to reduce your confusion n which python you are using you could try the following 2 commands in Linux or mac where bash shell is installed:

$ which python or $ which python3

in my case, it outputs the python paths I am using with pyenv [with fish shell] [$ is a shell sign]

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM