Anaconda 配置虛擬環境

Anaconda與conda區別
conda可以理解為一個工具,也是一個可執行命令,其核心功能是包管理與環境管理。包管理與pip的使用類似,環境管理則允許用戶方便地安裝不同版本的python并可以快速切換。 conda的設計理念——conda將幾乎所有的工具、第三方包都當做package對待,甚至包括python和conda自身 Anaconda則是一個打包的集合,里面預裝好了conda、某個版本的python、眾多packages、科學計算工具等等

1 查找虛擬環境

conda info --envs 或者或** conda info -e**

2 選擇虛擬環境

source activate py35_pytorch

3 退出虛擬環境

source deactivate py35_pytorch

4 安裝librosa

conda install -c conda-forge librosa

1.首先,我們可以檢查以查看哪些版本的Python可供我們使用:

conda search "^python$"

您將收到包含您可以定位的不同版本的Python的輸出,包括Python3和Python2版本。由于我們在本教程中使用Anaconda與Python 3,您將只能訪問Python 3版本的軟件包。

讓我們使用最新版本的Python 3創建一個環境。我們可以通過將版本3分配給python參數來實現。 我們將調用環境py2-env ,但是您可能希望為您的環境使用更具描述性的名稱,特別是如果您使用環境來訪問多個版本的Python。

conda create --name py35_pytorch python=3.5

我們將收到輸出,包含有關下載內容和要安裝的軟件包的信息,然后提示您繼續執行y或n 。 只要你同意,鍵入y 。

conda實用程序現在將獲取環境的包,并讓它知道什么時候完成。

2.windows可以通過鍵入以下內容激活新環境:
默認路徑為C:\Users\asus\Anaconda3\envs\py2-env

 To activate this environment, use: > activate py35_pytorch  To deactivate this environment, use: > deactivate py35_pytorch

ubuntu通過以下激活或停用

source activate my_envsource deactivate

3.此外,你可以通過以下命令,將虛擬環境安裝到指定路徑

conda create --prefix=D:\python36\py36 python=3.6

路徑D:\python36是先建好的文件夾,py36是需要安裝的虛擬環境名稱。請注意,安裝完成后,虛擬環境的全稱包含整個路徑,為D:\python36\py36。激活指定路徑下的虛擬環境的命令如下:

activate D:\python36\py36

想要刪除指定路徑下的虛擬環境,使用如下的命令:

conda remove --prefix=D:\python36\py36 --all
這里寫圖片描述

4.通過以下命令查看已建好的環境

conda info --envs

5.對虛擬環境中安裝額外的包。
使用命令conda install -n your_env_name [package]即可安裝package到your_env_name中,例如numpy :

conda install --name py2-env python=3.5 numpy

6.如果你知道你想創建一個numpy環境,你可以在conda conda create命令:

conda create --name my_env python=3.5 numpy

7.如果您不再處理特??定項目,并且不再需要相關環境,則可以將其刪除。為此,請鍵入以下內容:

conda remove --name py2-env --all

現在,當您鍵入conda info --envs命令時,您刪除的環境將不再列出。
8.刪除環境中的某個包。
使用命令conda remove --name your_env_namepackage_name 即可。
9、設置國內鏡像
如果需要安裝很多packages,你會發現conda下載的速度經常很慢,因為Anaconda.org的服務器在國外。所幸的是,清華TUNA鏡像源有Anaconda倉庫的鏡像,我們將其加入conda的配置即可:

添加Anaconda的TUNA鏡像

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

TUNA的help中鏡像地址加有引號,需要去掉

設置搜索時顯示通道地址

conda config --set show_channel_urls yes

$ export ENV_NAME="py35_pytorch"  # or any other name you prefer$ conda create --name $ENV_NAME --file all_pkg_versions.txt python=3.5 anaconda$ source activate $ENV_NAME

補充:help

~$ conda create --helpusage: conda create [-h] [-y] [--dry-run] [-f] [--file FILE] [--no-deps]                    [--only-deps] [-m] [-C] [--use-local] [--offline]                    [--no-pin] [-c CHANNEL] [--override-channels]                    [-n ENVIRONMENT | -p PATH] [-q] [--copy] [-k]                    [--update-dependencies] [--no-update-dependencies]                    [--channel-priority] [--no-channel-priority] [--clobber]                    [--show-channel-urls] [--no-show-channel-urls]                    [--download-only] [--json] [--debug] [--verbose]                    [--clone ENV] [--no-default-packages]                    [package_spec [package_spec ...]]Create a new conda environment from a list of specified packages. To use the created environment, use 'source activate envname' look in that directory first.  This command requires either the -n NAME or -p PREFIX option. Options: positional arguments:  package_spec          Packages to install or update in the conda environment.optional arguments:  -h, --help            Show this help message and exit.  -y, --yes             Do not ask for confirmation.  --dry-run             Only display what would have been done.  -f, --force           Force install (even when package already installed).  --file FILE           Read package versions from the given file. Repeated file specifications can be passed                        e.g. --file=file1 --file=file2).  --no-deps             Do not install, update, remove, or change                        dependencies. This WILL lead to broken environments                        and inconsistent behavior. Use at your own risk  --only-deps           Only install dependencies.  -m, --mkdir           Create the environment directory if necessary.  -C, --use-index-cache                        Use cache of channel index files, even if it has expired.  --use-local           Use locally built packages.  --offline             Offline mode, don't connect to the Internet.  --no-pin              Ignore pinned file.  -c CHANNEL, --channel CHANNEL                        Additional channel to search for packages. These are                        URLs searched in the order they are given (including                        file:// for local directories). Then, the defaults or                        channels from .condarc are searched (unless                        --override-channels is given). You can use 'defaults'                        to get the default packages for conda, and 'system' to                        get the system packages, which also takes .condarc                        into account. You can also use any name and the                        .condarc channel_alias value will be prepended. The                        default channel_alias is http://conda.anaconda.org/.  --override-channels   Do not search default or .condarc channels. Requires                        --channel.  -n ENVIRONMENT, --name ENVIRONMENT                        Name of environment.  -p PATH, --prefix PATH                        Full path to environment prefix.  -q, --quiet           Do not display progress bar.  --copy                Install all packages using copies instead of hard- or                        soft-linking.  -k, --insecure        Allow conda to perform "insecure" SSL connections and                        transfers. Equivalent to setting 'ssl_verify' to 'false'.  --update-dependencies, --update-deps                        Update dependencies. Overrides the value given by                        `conda config --show update_deps`.  --no-update-dependencies, --no-update-deps                        Don't update dependencies. Overrides the value given                        by `conda config --show update_deps`.  --channel-priority, --channel-pri, --chan-pri                        Channel priority takes precedence over package                        version. Overrides the value given by `conda config                        --show channel_priority`.  --no-channel-priority, --no-channel-pri, --no-chan-pri                        Package version takes precedence over channel                        priority. Overrides the value given by `conda config                        --show channel_priority`.  --clobber             Allow clobbering of overlapping file paths within                        packages, and suppress related warnings.  --show-channel-urls   Show channel urls. Overrides the value given by `conda                        config --show show_channel_urls`.  --no-show-channel-urls                        Don't show channel urls. Overrides the value given by                        `conda config --show show_channel_urls`.  --download-only       Solve an environment and ensure package caches are                        populated, but exit prior to unlinking and linking                        packages into the prefix.  --json                Report all output as json. Suitable for using conda                        programmatically.  --debug               Show debug output.  --verbose, -v         Use once for info, twice for debug, three times for trace.  --clone ENV           Path to (or name of) existing local environment.  --no-default-packages                        Ignore create_default_packages in the .condarc file. Examples:    conda create -n myenv sqlite
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容