conda配置python混合开发环境一站式入门【全平台】

下载安装

Windows

直接下载安装包,下载完,直接下一步默认安装就好。

Linux or Mac

直接下载脚本,然后直接sh xxxx.sh安装就ok了

基本命令

#查看版本
conda info —envs
或
conda env list

# 安装完整版python2版本的conda
conda create -n py2 python=2 anaconda

# 移除虚拟环境
conda remove --all -n 3todo

# 创建只有django的python2环境,名字py2-dj,注意,python=2 django是连续参数
conda create python=2 django -n py2-dj

# 如果不指定python版本,那是不能够滴,会报错
conda create -n env-test
Error: too few arguments, must supply command line package specs or --file

# 所以要至少指定个pytohn版本,可以不带任何库
conda create -n env-test python=3
Fetching package metadata .......

自定义命令别名

下面是我自己编的,你可以自定义。然后放到.bashrc,或.bash_profile就可以了!

linux或mac

# alias for conda
 alias cl="conda env list"
 alias cc="conda create -n"
 alias coa="source activate"
 alias cod="source deactivate"
 alias cr="conda remove --all -n"

注意:对于Linux,最好自己添加一下环境变量,conda的脚本执行完,也会提醒你的。
添加下面这行到.bashrc

export PATH=/root/anaconda3/bin:$PATH

最后别忘了重新加载一下。

source ~/.bashrc

Windows最好配合ConEmu使用

在settings->Startup>Environment

alias cl=conda env list
alias cc=conda create -n $*
alias coa=activate $*
alias cod=deactivate
alias cr=conda remove --all -n $*

在mac中的使用示例

建立py3-dj,使用和删除的整个过程

-------
~ cc py3-dj python=3 django
Fetching package metadata .......
Solving package specifications: ..........

Package plan for installation in environment /Users/howie/anaconda3/envs/py3-dj:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    django-1.9.5               |           py35_0         3.6 MB
    setuptools-26.1.1          |           py35_0         524 KB
    ------------------------------------------------------------
                                           Total:         4.1 MB

The following NEW packages will be INSTALLED:

    django:     1.9.5-py35_0
    openssl:    1.0.2h-2
    pip:        8.1.2-py35_0
    python:     3.5.2-0
    readline:   6.2-2
    setuptools: 26.1.1-py35_0
    sqlite:     3.13.0-0
    tk:         8.5.18-0
    wheel:      0.29.0-py35_0
    xz:         5.2.2-0
    zlib:       1.2.8-3

Proceed ([y]/n)? y

Fetching packages ...
django-1.9.5-p 100% |################################| Time: 0:00:08 437.51 kB/s
setuptools-26. 100% |################################| Time: 0:00:03 154.73 kB/s
Extracting packages ...
[      COMPLETE      ]|###################################################| 100%
Linking packages ...
[      COMPLETE      ]|###################################################| 100%
#
# To activate this environment, use:
# $ source activate py3-dj
#
# To deactivate this environment, use:
# $ source deactivate
#
➜  ~ cl
# conda environments:
#
py2                      /Users/howie/anaconda3/envs/py2
py2-dj                   /Users/howie/anaconda3/envs/py2-dj
py3-dj                   /Users/howie/anaconda3/envs/py3-dj
root                  *  /Users/howie/anaconda3

➜  ~ coa py3-dj
(py3-dj) ➜  ~ python
Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.__version__
'1.9.5'
>>>
(py3-dj) ➜  ~ cod
➜  ~ cl
# conda environments:
#
py2                      /Users/howie/anaconda3/envs/py2
py2-dj                   /Users/howie/anaconda3/envs/py2-dj
py3-dj                   /Users/howie/anaconda3/envs/py3-dj
root                  *  /Users/howie/anaconda3

➜  ~ cr py3-dj

Package plan for package removal in environment /Users/howie/anaconda3/envs/py3-dj:

The following packages will be REMOVED:

    django:     1.9.5-py35_0
    openssl:    1.0.2h-2
    pip:        8.1.2-py35_0
    python:     3.5.2-0
    readline:   6.2-2
    setuptools: 26.1.1-py35_0
    sqlite:     3.13.0-0
    tk:         8.5.18-0
    wheel:      0.29.0-py35_0
    xz:         5.2.2-0
    zlib:       1.2.8-3

Proceed ([y]/n)? y

Unlinking packages ...
[      COMPLETE      ]|###################################################| 100%
    原文作者:第8哥
    原文地址: https://www.cnblogs.com/de8ug/p/conda-python.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞