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%


免責聲明!

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



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