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

你。 提交于 2020-02-25 13:54:35

问题


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?


回答1:


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.




回答2:


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/




回答3:


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/




回答4:


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)

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



回答5:


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.




回答6:


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



回答7:


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!




回答8:


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:

  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:

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



来源:https://stackoverflow.com/questions/58348155/how-to-compile-gcc-on-macos-catalina

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!