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:
$ pip freeze > requirements.txt
$ rm -rf .venv
$ deactivate
$ virtualenv -p python3 .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With