Anaconda與conda區(qū)別
conda可以理解為一個(gè)工具,也是一個(gè)可執(zhí)行命令,其核心功能是包管理與環(huán)境管理。包管理與pip的使用類似,環(huán)境管理則允許用戶方便地安裝不同版本的python并可以快速切換。 conda的設(shè)計(jì)理念——conda將幾乎所有的工具、第三方包都當(dāng)做package對(duì)待,甚至包括python和conda自身 Anaconda則是一個(gè)打包的集合,里面預(yù)裝好了conda、某個(gè)版本的python、眾多packages、科學(xué)計(jì)算工具等等
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版本。由于我們?cè)诒窘坛讨惺褂肁naconda與Python 3,您將只能訪問(wèn)Python 3版本的軟件包。
讓我們使用最新版本的Python 3創(chuàng)建一個(gè)環(huán)境。我們可以通過(guò)將版本3分配給python參數(shù)來(lái)實(shí)現(xiàn)。 我們將調(diào)用環(huán)境py2-env ,但是您可能希望為您的環(huán)境使用更具描述性的名稱,特別是如果您使用環(huán)境來(lái)訪問(wèn)多個(gè)版本的Python。
conda create --name py35_pytorch python=3.5
我們將收到輸出,包含有關(guān)下載內(nèi)容和要安裝的軟件包的信息,然后提示您繼續(xù)執(zhí)行y或n 。 只要你同意,鍵入y 。
conda實(shí)用程序現(xiàn)在將獲取環(huán)境的包,并讓它知道什么時(shí)候完成。
2.windows可以通過(guò)鍵入以下內(nèi)容激活新環(huán)境:
默認(rè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通過(guò)以下激活或停用
source activate my_envsource deactivate
3.此外,你可以通過(guò)以下命令,將虛擬環(huán)境安裝到指定路徑
conda create --prefix=D:\python36\py36 python=3.6
路徑D:\python36是先建好的文件夾,py36
是需要安裝的虛擬環(huán)境名稱。請(qǐng)注意,安裝完成后,虛擬環(huán)境的全稱包含整個(gè)路徑,為D:\python36\py36。激活指定路徑下的虛擬環(huán)境的命令如下:
activate D:\python36\py36
想要?jiǎng)h除指定路徑下的虛擬環(huán)境,使用如下的命令:
conda remove --prefix=D:\python36\py36 --all
4.通過(guò)以下命令查看已建好的環(huán)境
conda info --envs
5.對(duì)虛擬環(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)建一個(gè)numpy環(huán)境,你可以在conda conda create命令:
conda create --name my_env python=3.5 numpy
7.如果您不再處理特??定項(xiàng)目,并且不再需要相關(guān)環(huán)境,則可以將其刪除。為此,請(qǐng)鍵入以下內(nèi)容:
conda remove --name py2-env --all
現(xiàn)在,當(dāng)您鍵入conda info --envs
命令時(shí),您刪除的環(huán)境將不再列出。
8.刪除環(huán)境中的某個(gè)包。
使用命令conda remove --name package_name 即可。
9、設(shè)置國(guó)內(nèi)鏡像
如果需要安裝很多packages,你會(huì)發(fā)現(xiàn)conda下載的速度經(jīng)常很慢,因?yàn)锳naconda.org的服務(wù)器在國(guó)外。所幸的是,清華TUNA鏡像源有Anaconda倉(cāng)庫(kù)的鏡像,我們將其加入conda的配置即可:
添加Anaconda的TUNA鏡像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
TUNA的help中鏡像地址加有引號(hào),需要去掉
設(shè)置搜索時(shí)顯示通道地址
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
補(bǔ)充: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