Anaconda與conda區(qū)別
conda可以理解為一個工具,也是一個可執(zhí)行命令幌衣,其核心功能是包管理與環(huán)境管理。包管理與pip的使用類似,環(huán)境管理則允許用戶方便地安裝不同版本的python并可以快速切換泪漂。 conda的設計理念——conda將幾乎所有的工具、第三方包都當做package對待歪泳,甚至包括python和conda自身 Anaconda則是一個打包的集合萝勤,里面預裝好了conda、某個版本的python呐伞、眾多packages敌卓、科學計算工具等等
1 查找虛擬環(huán)境
conda info --envs 或者或** conda info -e**
2 選擇虛擬環(huán)境
source activate py35_pytorch
3 退出虛擬環(huán)境
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創(chuàng)建一個環(huán)境舵抹。我們可以通過將版本3分配給python參數(shù)來實現(xiàn)。 我們將調(diào)用環(huán)境py2-env 劣砍,但是您可能希望為您的環(huán)境使用更具描述性的名稱惧蛹,特別是如果您使用環(huán)境來訪問多個版本的Python。
conda create --name py35_pytorch python=3.5
我們將收到輸出,包含有關(guān)下載內(nèi)容和要安裝的軟件包的信息香嗓,然后提示您繼續(xù)執(zhí)行y或n 迅腔。 只要你同意,鍵入y 靠娱。
conda實用程序現(xiàn)在將獲取環(huán)境的包沧烈,并讓它知道什么時候完成。
2.windows可以通過鍵入以下內(nèi)容激活新環(huán)境:
默認路徑為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.此外,你可以通過以下命令,將虛擬環(huán)境安裝到指定路徑
conda create --prefix=D:\python36\py36 python=3.6
路徑D:\python36是先建好的文件夾像云,py36
是需要安裝的虛擬環(huán)境名稱锌雀。請注意,安裝完成后迅诬,虛擬環(huán)境的全稱包含整個路徑腋逆,為D:\python36\py36。激活指定路徑下的虛擬環(huán)境的命令如下:
activate D:\python36\py36
想要刪除指定路徑下的虛擬環(huán)境侈贷,使用如下的命令:
conda remove --prefix=D:\python36\py36 --all
4.通過以下命令查看已建好的環(huán)境
conda info --envs
5.對虛擬環(huán)境中安裝額外的包惩歉。
使用命令conda install -n your_env_name [package]即可安裝package到y(tǒng)our_env_name中,例如numpy :
conda install --name py2-env python=3.5 numpy
6.如果你知道你想創(chuàng)建一個numpy環(huán)境,你可以在conda conda create命令:
conda create --name my_env python=3.5 numpy
7.如果您不再處理特??定項目俏蛮,并且不再需要相關(guān)環(huán)境撑蚌,則可以將其刪除。為此搏屑,請鍵入以下內(nèi)容:
conda remove --name py2-env --all
現(xiàn)在争涌,當您鍵入conda info --envs
命令時,您刪除的環(huán)境將不再列出睬棚。
8.刪除環(huán)境中的某個包第煮。
使用命令conda remove --name package_name 即可解幼。
9抑党、設置國內(nèi)鏡像
如果需要安裝很多packages,你會發(fā)現(xiàn)conda下載的速度經(jīng)常很慢撵摆,因為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