Max OS 利用Anaconda管理包版本環(huán)境

? ? 在Python中令人最令人頭疼的問(wèn)題之一就是Python版本的問(wèn)題,Python 2.7 和Python 3.x存在一些沖突。尤其當(dāng)安裝Numpy包時(shí),如果存在沖突,會(huì)產(chǎn)生一系列的麻煩。

? ?PyCharm是一款優(yōu)秀的Python IDE,但是PyCharm在包和版本管理上,實(shí)現(xiàn)較為麻煩。更好的方法是,采用專門(mén)的環(huán)境管理軟件Anaconda。本文就是在Pycharm 的基礎(chǔ)上,利用Anaconda實(shí)現(xiàn)。



一 軟件下載、安裝

Python PyCharm不再贅述

Anaconda:其官方網(wǎng)速過(guò)慢,我們從清華鏡像中下載,其中有兩個(gè)版本 .pkg是GUI .sh需要用 command line 安裝

二 在Pycharm中配置Anaconda環(huán)境

PyCharm->Preferences->Project Interpreter->齒輪按鈕->add local->System Interpreter->User/Local/bin/Python 2.7

OJBK

選擇Interpreter

三 Conda操作及簡(jiǎn)單指令

安裝完Conda之后,在terminal中鍵入 Conda之后可以查看簡(jiǎn)單介紹,如下所示

clean? ? ? ? Remove unused packages and caches.

? ? config? ? ? Modify configuration values in .condarc. This is modeled

?? ? ? ? ? ? ? ? after the git config command. Writes to the user .condarc

?? ? ? ? ? ? ? ? file (/Users/yajungu/.condarc) by default.

? ? create? ? ? Create a new conda environment from a list of specified

?? ? ? ? ? ? ? ? packages.

? ? help? ? ? ? Displays a list of available conda commands and their help

?? ? ? ? ? ? ? ? strings.

? ? info? ? ? ? Display information about current conda install.

? ? install? ? ? Installs a list of packages into a specified conda

?? ? ? ? ? ? ? ? environment.

? ? list? ? ? ? List linked packages in a conda environment.

? ? package? ? ? Low-level conda package utility. (EXPERIMENTAL)

? ? remove? ? ? Remove a list of packages from a specified conda environment.

? ? uninstall? ? Alias for conda remove. See conda remove --help.

? ? search? ? ? Search for packages and display associated information. The

?? ? ? ? ? ? ? ? input is a MatchSpec, a query language for conda packages.

?? ? ? ? ? ? ? ? See examples below.

? ? update? ? ? Updates conda packages to the latest compatible version. This

?? ? ? ? ? ? ? ? command accepts a list of package names and updates them to

?? ? ? ? ? ? ? ? the latest versions that are compatible with all other

?? ? ? ? ? ? ? ? packages in the environment. Conda attempts to install the

?? ? ? ? ? ? ? ? newest versions of the requested packages. To accomplish

?? ? ? ? ? ? ? ? this, it may update some packages that are already installed,

?? ? ? ? ? ? ? ? or install additional packages. To prevent existing packages

?? ? ? ? ? ? ? ? from updating, use the --no-update-deps option. This may

?? ? ? ? ? ? ? ? force conda to install older versions of the requested

?? ? ? ? ? ? ? ? packages, and it does not prevent additional dependency

?? ? ? ? ? ? ? ? packages from being installed. If you wish to skip dependency

?? ? ? ? ? ? ? ? checking altogether, use the '--force' option. This may

?? ? ? ? ? ? ? ? result in an environment with incompatible packages, so this

?? ? ? ? ? ? ? ? option must be used with great caution.

? ? upgrade? ? ? Alias for conda update. See conda update --help.

optional arguments:

? -h, --help? ? Show this help message and exit.

? -V, --version? Show the conda version number and exit.

應(yīng)用舉例:

(1)創(chuàng)建Python 3.6的版本,取名為 py36:

conda create -n py36 python=3.6

(2)刪除環(huán)境

conda remove -n py36 --all

?(3)激活環(huán)境

source activate py36

?(4)激活環(huán)境 退出環(huán)境

source deactivate

如果你安裝的是GUI版本,你可以簡(jiǎn)單的利用圖形界面操作,不推薦,我嘗試多次沒(méi)有成功

四 解決HTTP 000

創(chuàng)建環(huán)境過(guò)程中,可能會(huì)出現(xiàn) HTTP 000 error的問(wèn)題

Fetching package metadata .......

CondaHTTPError: HTTP 000 CONNECTION FAILED for url

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'

原因就是鏈接不到Conda的官網(wǎng)

解決方案:沒(méi)錯(cuò),依然利用清華鏡像

具體步驟,terminal下

(1)添加清華鏡像

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

(2)查看配置文件中的內(nèi)容

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/

? - https://nanomirrors.tuna.tsinghua.edu.cn/anaconda/cloud

? - defaults

除了四個(gè)鏡像之外,還存在一個(gè)Defaults,error就是由它引起的,刪除這一條

(3)利用vim刪除defaults

vim ~/.condarc?

選擇 e進(jìn)入編輯模式 :

鍵入 i 進(jìn)行編輯,刪除 “-Defaults”

esc退出編輯

:wq保存退出

OK問(wèn)題解決!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 什么是成熟? ——喜歡的東西依舊喜歡,但可以不擁有;害怕的東西依舊害怕,但可以面對(duì)。 ?
    FenniferShi閱讀 172評(píng)論 0 1
  • 2016.08.14 星期天 陽(yáng)光燦爛 今天的安排是取模拔牙,取完模之后當(dāng)我躺下去的時(shí)候李醫(yī)生聽(tīng)到我在吸鼻子,問(wèn)我...
    吃貨霞閱讀 280評(píng)論 0 0

友情鏈接更多精彩內(nèi)容