Pycharm使用Conda Environment添加conda虛擬環境(MAC版)


首先在conda內通過conda create創建一個虛擬環境:conda create -n deeplearning python=3.6.8/conda create -n deeplearning python=3.6效果相同,均可創建;

打開pycharm,左上角Pycharm -> Preference -> Project Interpreter -> 右上角小齒輪的Add->選擇Existing Environment,Interperter定位/…/anaconda3/envs/deeplearning/bin/python3.6,如下:
-->-->-->-->

緊接着確認即可,等待配置完成,如下:

 .

完結!

但!如果你第一步就卡住了,請關注如下內容:

問題描述:conda無法創建虛擬環境並且無法安裝其他第三方包,報錯內容如下:

conda create -n deeplearning python=3.6

Fetching package metadata .......
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://nanomirrors.tuna.tsinghua.edu.cn/anaconda/cloud/linux-64/rpodata.json>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
ConnectTimeout(MaxRetryError("HTTPSConnectionPool(host='nanomirrors.tuna.tsinghua.edu.cn', port=443): Max retries exceded with url: /anaconda/cloud/linux-64/repodata.json (Caused by ConnectTimeoutError(<requests.packages.urllib3.connecton.VerifiedHTTPSConnection object at 0x7fb6d340dcc0>, 'Connection to nanomirrors.tuna.tsinghua.edu.cn timed out. (connct timeout=9.15)'))",),)

2.錯誤原因:默認鏡像源訪問速度過慢,會導致超時從而導致更新和下載失敗。

3.解決方案:更換鏡像源為清華鏡像源,並且刪除默認鏡像源。

#首先先添加清華的鏡像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes

 #如果還是有問題,可以試試以下中科大的其他鏡像源:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

#注:網上可以發現很多鏡像都可用,試用的時候最好不要混合,一種一種去試。

3.2.更改鏡像源配置文件

#在用戶根目錄(‎⁨Macintosh HD⁩/用戶⁩(Users)/any⁩)下找到.condarc文件,打開並並編輯,刪除其中的default配置行。其中.condarc文件被隱藏,顯示方法為‘Command+Shift+. ’,再按一次,恢復隱藏。

#1、查看配置文件的內容
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
- defaults
show_channel_urls: true

#2、刪除部分內容
## 主要是刪除此行: - defaults
#修改后配置文件的內容如下:
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
show_channel_urls: true

4.重新創建虛擬環境,成功!

 

參考:https://blog.csdn.net/qq_29768741/article/details/105846135

   https://blog.csdn.net/Copper01/article/details/97134974

   https://blog.csdn.net/ada0915/article/details/78529877

   https://www.jianshu.com/p/c74668743932


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM