Max OS 利用Anaconda管理包版本环境

    在Python中令人最令人头疼的问题之一就是Python版本的问题,Python 2.7 和Python 3.x存在一些冲突。尤其当安装Numpy包时,如果存在冲突,会产生一系列的麻烦。

   PyCharm是一款优秀的Python IDE,但是PyCharm在包和版本管理上,实现较为麻烦。更好的方法是,采用专门的环境管理软件Anaconda。本文就是在Pycharm 的基础上,利用Anaconda实现。



一 软件下载、安装

Python PyCharm不再赘述

Anaconda:其官方网速过慢,我们从清华镜像中下载,其中有两个版本 .pkg是GUI .sh需要用 command line 安装

二 在Pycharm中配置Anaconda环境

PyCharm->Preferences->Project Interpreter->齿轮按钮->add local->System Interpreter->User/Local/bin/Python 2.7

OJBK

选择Interpreter

三 Conda操作及简单指令

安装完Conda之后,在terminal中键入 Conda之后可以查看简单介绍,如下所示

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.

应用举例:

(1)创建Python 3.6的版本,取名为 py36:

conda create -n py36 python=3.6

(2)删除环境

conda remove -n py36 --all

 (3)激活环境

source activate py36

 (4)激活环境 退出环境

source deactivate

如果你安装的是GUI版本,你可以简单的利用图形界面操作,不推荐,我尝试多次没有成功

四 解决HTTP 000

创建环境过程中,可能会出现 HTTP 000 error的问题

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的官网

解决方案:没错,依然利用清华镜像

具体步骤,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)查看配置文件中的内容

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

除了四个镜像之外,还存在一个Defaults,error就是由它引起的,删除这一条

(3)利用vim删除defaults

vim ~/.condarc 

选择 e进入编辑模式 :

键入 i 进行编辑,删除 “-Defaults”

esc退出编辑

:wq保存退出

OK问题解决!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,524评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,869评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,813评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,210评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,085评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,117评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,533评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,219评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,487评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,582评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,362评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,218评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,589评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,899评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,176评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,503评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,707评论 2 335

推荐阅读更多精彩内容

  • 什么是成熟? ——喜欢的东西依旧喜欢,但可以不拥有;害怕的东西依旧害怕,但可以面对。 ​
    FenniferShi阅读 135评论 0 1
  • 2016.08.14 星期天 阳光灿烂 今天的安排是取模拔牙,取完模之后当我躺下去的时候李医生听到我在吸鼻子,问我...
    吃货霞阅读 224评论 0 0