rrz0
rrz0

Reputation: 2302

How to get Conda and Virtualenv to work on mac OS Catalina?

I previously had Conda running smoothly on Mojave, but I've found that the upgrade to Catalina moves the "anaconda3" folder to your Desktop > Relocated Items > Security > anaconda3. It seems Catalina's security settings may not allow applications to install directly under the user directory anymore.

I tried the suggestion here, written below:

Hi, I might have a solution

  • Copy the folder anaconda3 located in Relocated Items to /Users/myname/
  • Open Terminal
  • Enter: export PATH=''/Users/myname/anaconda3/bin:$PATH"
  • Enter: conda init zsh

It worked! Good luck!

But this doesn't work for me. After conda init zsh I get:

-bash: /Users/USER/anaconda3/bin/conda: /anaconda3/bin/python: bad interpreter: No such file or directory

How can I get Conda up and running again without losing all my virtual environments? Thanks!


Update

I got Conda to work following @Ted Shaowang's suggestion. This means that conda env list shows all the virtual environments created via Conda.

However I am still experiencing an issue with virtualenv as since I changed the default anaconda3 file locations, python cannot be found.

The python executable located at .virtualenvs/env/bin/python cannot be found. Do I need to make further changes in order for python to work from virtualenv too?

Upvotes: 15

Views: 13402

Answers (8)

rrz0
rrz0

Reputation: 2302

This is what worked for me.

These are my header files (Catalina 10.15):

/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h

Run sudo find /Library -name stdio.h to see where yours are located.

Mojave 10.14 header files:

$ sudo find /Library -name stdio.h 
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h

As can be seen the SDKs are now split into MACOSX10.14 and 10.15 unlike in Mojave.

TLDR

So, these were my SDK folders on Catalina:

<img width="208" alt="image" src="https://user-images.githubusercontent.com/31866965/67324292-e49a1e00-f513-11e9-997e-9c49e7badbe5.png">

  1. Rename MacOSX.sdk to MacOSX_orig.sdk
  2. Right click on MacOSX10.14.sdk
  3. Duplicate
  4. Rename duplicate folder to MacOSX.sdk

Your folder structure should now look like this:

<img width="195" alt="image" src="https://user-images.githubusercontent.com/31866965/67318914-74d46500-f50c-11e9-879d-ef0cd3e458cc.png">

Like this we are basically using the previous version's OSX sdk as sysroot. Hope this helps.

Upvotes: 0

Ted Shaowang
Ted Shaowang

Reputation: 314

I have the exact same problem and this works for me:

After you move anaconda from "Relocated Items" to ~/anaconda3, edit the first line of ~/anaconda3/bin/conda file from #!/anaconda3/bin/python to #!/Users/USERNAME/anaconda3/bin/python to reflect the change.

Upvotes: 7

msarahan
msarahan

Reputation: 1081

No solution will be completely working without fixing the baked-in hard-coded prefix entries in files. There's a longer description and a recommended fix at https://www.anaconda.com/how-to-restore-anaconda-after-macos-catalina-update/

Upvotes: 3

shreyas labhsetwar
shreyas labhsetwar

Reputation: 53

I had incurred the same issue, and the following solution worked for me, and this is the easiest solution:

Instead of messing around copying the anaconda3 file from relocated items into User/USERNAME directory, better would be just to reinstall anaconda navigator's latest version from its official website : https://www.anaconda.com/distribution/#macos

While installation, it will ask you some permissions which are a result of new Apple Security Policies, just grant them, and it works just the way it should after this fresh installation!

Upvotes: 0

TANK NK
TANK NK

Reputation: 1

I have the same problem, and this work for me : My solution:

  1. Copy your anaconda3 from Relocated Items folder
  2. Paste in User/YourUserName
  3. Open conda file in anaconda3/bin with the editor and edit the first line #!/anaconda3/bin/python to #!/Users/YourUserName/anaconda3/bin/python
  4. Save it and run conda file
  5. Open Terminal
  6. Run this : export PATH=''/Users/YourUserName/anaconda3/bin:$PATH"
  7. Run conda init zsh

Upvotes: 0

Phil S
Phil S

Reputation: 195

Technically this is reinstalling anaconda, however, I restored all my conda envs so, hopefully this is an acceptable solution!

Here is how I got it working on Catalina as of a few minutes ago (now using z-shell): - Verified the existence of "Relocated Items" directory on my desktop and the "anaconda3" directory and its contents inside - Navigated into the envs directory under "anaconda3" and left the finder window open (see screenshot)

enter image description here

THEN:

  • opened new Terminal (z-shell)
  • ran (this installed to /usr/local/anaconda3):

    brew cask install anaconda

  • after installation was successful I opened my ~/.zshrc file (for my z-shell aliases) and added the following line:

    export PATH="/usr/local/anaconda3/bin:$PATH"

  • saved my ~/.zshrc file, then reloaded with:

    source ~/.zshrc

  • to verify conda command works now, I ran:

    conda env list

  • for me, this showed a base env and that was it

  • then open Finder to the new envs location: open /usr/local/anaconda3/envs/.

  • I dragged (moved) all my old envs into the new envs folder, and then ran:

    conda env list

And all my old envs are back! :)

  • updated my PyCharm interpreter / env paths to reflect the new locations of these envs (had to restart PyCharm after, but now it works!)
  • DONE

Upvotes: 1

Sean Wangnick
Sean Wangnick

Reputation: 3

Unsure whether this is considered a comment or at least a temporary answer, but I would refrain from attempting to fix any Catalina compatibility issues with Anaconda for now. See this GitHub issue.

Upvotes: 0

Cristina Morariu
Cristina Morariu

Reputation: 415

I would probably abstain from using the above solution. That ~/anaconda3/bin directory has lots of runnables (not just the conda one) that would need to be altered in this manual way. For example, unless you make the same change you cannot run jupyter notebook either, neither from base nor from other envs you might have.

My tip: Try getting a requirements file for your virtual envs, and do a fresh installation. You could use pipreqs to get the requirements used for individual projects: https://www.idiotinside.com/2015/05/10/python-auto-generate-requirements-txt/

Upvotes: 3

Related Questions