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问题解决!