介绍 (Introduction)
Designed for data science and machine learning workflows, Anaconda is an open-source package manager, environment manager, and distribution of the Python and R programming languages. It is commonly used for large-scale data processing, scientific computing, and predictive analytics.
Anaconda专为数据科学和机器学习工作流而设计,是一个开源软件包管理器,环境管理器以及Python和R编程语言的发行版。 它通常用于大规模数据处理,科学计算和预测分析。
Offering a collection of over 1,000 data science packages, Anaconda is available in both free and paid enterprise versions. The Anaconda distribution ships with the conda
command-line utility. You can learn more about Anaconda and conda
by reading the official Anaconda Documentation.
Anaconda提供了1000多种数据科学软件包的集合,有免费和付费企业版。 Anaconda发行版随附conda
命令行实用程序。 您可以通过阅读Anaconda官方文档了解有关Anaconda和conda
的更多信息。
This tutorial will guide you through installing the Python 3 version of Anaconda on an Ubuntu 18.04 server.
本教程将指导您在Ubuntu 18.04服务器上安装Anaconda的Python 3版本。
先决条件 (Prerequisites)
Before you begin with this guide, you should have a non-root user with sudo privileges set up on your server.
在开始本指南之前,您应该在服务器上设置具有sudo特权的非root用户。
You can achieve this prerequisite by completing our Ubuntu 18.04 initial server setup guide.
您可以通过完成我们的Ubuntu 18.04初始服务器设置指南来实现此先决条件。
安装Anaconda (Installing Anaconda)
The best way to install Anaconda is to download the latest Anaconda installer bash script, verify it, and then run it.
安装Anaconda的最佳方法是下载最新的Anaconda安装程序bash脚本,进行验证,然后运行它。
Find the latest version of Anaconda for Python 3 at the Anaconda Downloads page. At the time of writing, the latest version is 2019.03, but you should use a later stable version if it is available.
在Anaconda下载页面中找到适用于Python 3的最新版本的Anaconda。 在撰写本文时,最新版本是2019.03,但如果有可用的,则应使用更高的稳定版本。
Next, change to the /tmp
directory on your server. This is a good directory to download ephemeral items, like the Anaconda bash script, which we won’t need after running it.
接下来,转到服务器上的/tmp
目录。 这是下载临时项目(例如Anaconda bash脚本)的好目录,运行该目录后我们将不需要它。
- cd /tmp cd / tmp
Use curl
to download the link that you copied from the Anaconda website:
使用curl
下载您从Anaconda网站复制的链接:
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
curl -O https://repo.anaconda.com/archive/Anaconda3- 2019.03 -Linux-x86_64.sh
We can now verify the data integrity of the installer with cryptographic hash verification through the SHA-256 checksum. We’ll use the sha256sum
command along with the filename of the script:
现在,我们可以通过SHA-256校验和通过密码哈希验证来验证安装程序的数据完整性。 我们将使用sha256sum
命令以及脚本的文件名:
sha256sum Anaconda3-2019.03-Linux-x86_64.sh
sha256sum Anaconda3- 2019.03 -Linux-x86_64.sh
You’ll receive output that looks similar to this:
您将收到类似于以下内容的输出:
Output
45c851b7497cc14d5ca060064394569f724b67d9b5f98a926ed49b834a6bb73a Anaconda3-2019.03-Linux-x86_64.sh
You should check the output against the hashes available at the Anaconda with Python 3 on 64-bit Linux page for your appropriate Anaconda version. As long as your output matches the hash displayed in the sha2561
row, you’re good to go.
您应该对照64位Linux页面上带有Python 3的Anaconda上可用的哈希值检查输出,以找到合适的Anaconda版本。 只要您的输出与sha2561
行中显示的哈希匹配,就可以了。
Now we can run the script:
现在我们可以运行脚本:
bash Anaconda3-2019.03-Linux-x86_64.sh
bash Anaconda3- 2019.03 -Linux-x86_64.sh
You’ll receive the following output:
您将收到以下输出:
Output
Welcome to Anaconda3 2019.03
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
Press ENTER
to continue and then press ENTER
to read through the license. Once you’re done reading the license, you’ll be prompted to approve the license terms:
按ENTER
继续,然后按ENTER
阅读许可证。 阅读完许可证后,系统将提示您批准许可证条款:
Output
Do you approve the license terms? [yes|no]
As long as you agree, type yes
.
只要您同意,请输入yes
。
At this point, you’ll be prompted to choose the location of the installation. You can press ENTER
to accept the default location, or specify a different location to modify it.
此时,系统将提示您选择安装位置。 您可以按ENTER
接受默认位置,或指定其他位置进行修改。
Output
Anaconda3 will now be installed into this location:
/home/sammy/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/sammy/anaconda3] >>>
The installation process will continue. Note that it may take some time.
安装过程将继续。 请注意,这可能需要一些时间。
Once installation is complete, you’ll receive the following output:
安装完成后,您将收到以下输出:
Output
...
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/sammy/.bashrc ? [yes|no]
[no] >>>
Type yes
so that you can use the conda
command. You’ll receive the following output next:
键入yes
以便您可以使用conda
命令。 接下来,您将收到以下输出:
Output
Appending source /home/sammy/anaconda3/bin/activate to /home/sammy/.bashrc
A backup will be made to: /home/sammy/.bashrc-anaconda3.bak
...
You can now activate the installation by sourcing the ~/.bashrc
file:
现在,您可以通过采购~/.bashrc
文件来激活安装:
- source ~/.bashrc 来源〜/ .bashrc
Once you have done that, you can verify your install by making use of the conda
command, for example with list
:
完成此操作后,您可以使用conda
命令(例如,使用list
来验证安装:
- conda list conda清单
You’ll receive output of all the packages you have available through the Anaconda installation:
您将收到通过Anaconda安装可获得的所有软件包的输出:
Output
# packages in environment at /home/sammy/anaconda3:
#
# Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py37_0
alabaster 0.7.12 py37_0
anaconda 2019.03 py37_0
...
Now that Anaconda is installed, we can go on to setting up Anaconda environments.
现在已经安装了Anaconda,我们可以继续设置Anaconda环境。
设置Anaconda环境 (Setting Up Anaconda Environments)
Anaconda virtual environments allow you to keep projects organized by Python versions and packages needed. For each Anaconda environment you set up, you can specify which version of Python to use and can keep all of your related programming files together within that directory.
Anaconda虚拟环境使您可以按所需的Python版本和软件包组织项目。 对于您设置的每个Anaconda环境,您可以指定要使用的Python版本,并将所有相关的编程文件保存在该目录中。
First, we can check to see which versions of Python are available for us to use:
首先,我们可以检查一下哪些Python版本可供我们使用:
- conda search "^python$" conda搜索“ ^ python $”
You’ll receive output with the different versions of Python that you can target, including both Python 3 and Python 2 versions. Since we are using the Anaconda with Python 3 in this tutorial, you will have access only to the Python 3 versions of packages.
您将收到可以定位的不同Python版本的输出,包括Python 3和Python 2版本。 由于在本教程中我们将Anaconda与Python 3结合使用,因此您只能访问Python 3版本的软件包。
Let’s create an environment using the most recent version of Python 3. We can achieve this by assigning version 3 to the python
argument. We’ll call the environment my_env, but you’ll likely want to use a more descriptive name for your environment especially if you are using environments to access more than one version of Python.
让我们使用最新版本的Python 3创建环境。我们可以通过将版本3分配给python
参数来实现此目的。 我们将环境称为my_env ,但是您可能希望为您的环境使用更具描述性的名称,尤其是当您使用环境访问多个版本的Python时。
conda create --name my_env python=3
conda创建--name my_env python = 3
We’ll receive output with information about what is downloaded and which packages will be installed, and then be prompted to proceed with y
or n
. As long as you agree, type y
.
我们将收到输出,其中包含有关下载了哪些内容以及将要安装哪些软件包的信息,然后提示您继续进行y
或n
。 只要您同意,请输入y
。
The conda
utility will now fetch the packages for the environment and let you know when it’s complete.
conda
实用程序现在将获取环境的软件包,并在完成时通知您。
You can activate your new environment by typing the following:
您可以通过键入以下内容来激活新环境:
conda activate my_env
conda激活my_env
With your environment activated, your command prompt prefix will change:
激活环境后,命令提示符前缀将更改:
Within the environment, you can verify that you’re using the version of Python that you had intended to use:
在环境中,您可以验证您使用的是打算使用的Python版本:
- python --version python --version
Output
Python 3.7 :: Anaconda, Inc.
When you’re ready to deactivate your Anaconda environment, you can do so by typing:
当您准备停用Anaconda环境时,可以键入以下命令:
- conda deactivate conda停用
Note that you can replace the word source
with .
to achieve the same results.
请注意,您可以将单词source
替换为.
达到相同的结果。
To target a more specific version of Python, you can pass a specific version to the python
argument, like 3.5
, for example:
要定位特定版本的Python,您可以将特定版本传递给python
参数,例如3.5
,例如:
- conda create -n my_env35 python=3.5 conda创建-n my_env35 python = 3.5
You can update your version of Python along the same branch (as in updating Python 3.5.1 to Python 3.5.2) within a respective environment with the following command:
您可以使用以下命令在相应环境中的同一分支(如将Python 3.5.1更新为Python 3.5.2)中更新Python版本:
- conda update python conda更新Python
If you would like to target a more specific version of Python, you can pass that to the python
argument, as in python=3.3.2
.
如果您想针对更特定的Python版本,则可以将其传递给python
参数,如python=3.3.2
。
You can inspect all of the environments you have set up with this command:
您可以使用以下命令检查所有已设置的环境:
- conda info --envs conda信息--envs
Output
# conda environments:
#
base * /home/sammy/anaconda3
my_env /home/sammy/anaconda3/envs/my_env
my_env35 /home/sammy/anaconda3/envs/my_env35
The asterisk indicates the current active environment.
星号表示当前的活动环境。
Each environment you create with conda create
will come with several default packages:
您使用conda create
每个环境都将带有几个默认软件包:
openssl
openssl
pip
pip
python
python
readline
readline
setuptools
setuptools
sqlite
sqlite
tk
tk
wheel
wheel
xz
xz
zlib
zlib
You can add additional packages, such as numpy
for example, with the following command:
您可以使用以下命令添加其他软件包,例如numpy
:
conda install --name my_env35 numpy
conda安装--name my_env35 numpy
If you know you would like a numpy
environment upon creation, you can target it in your conda create
command:
如果知道在创建时需要一个numpy
环境,则可以在conda create
命令中将其定位:
- conda create --name my_env python=3 numpy conda创建--name my_env python = 3 numpy
If you are no longer working on a specific project and have no further need for the associated environment, you can remove it. To do so, type the following:
如果您不再从事特定项目并且不再需要关联的环境,则可以将其删除。 为此,请键入以下内容:
conda remove --name my_env35 --all
conda删除--name my_env35-全部
Now, when you type the conda info --envs
command, the environment that you removed will no longer be listed.
现在,当您键入conda info --envs
命令时,您删除的环境将不再列出。
更新水蟒 (Updating Anaconda)
You should regularly ensure that Anaconda is up-to-date so that you are working with all the latest package releases.
您应该定期确保Anaconda是最新的,以便使用所有最新的软件包版本。
To do this, you should first update the conda
utility:
为此,您应该首先更新conda
实用程序:
- conda update conda conda更新conda
When prompted to do so, type y
to proceed with the update.
当提示您这样做时,键入y
以继续进行更新。
Once the update of conda
is complete, you can update the Anaconda distribution:
conda
更新完成后,您可以更新Anaconda发行版:
- conda update anaconda conda更新Python
Again when prompted to do so, type y
to proceed.
再次提示您这样做时,键入y
继续。
This will ensure that you are using the latest releases of conda
and Anaconda.
这将确保您使用的是conda
和Anaconda的最新版本。
卸载Anaconda (Uninstalling Anaconda)
If you are no longer using Anaconda and find that you need to uninstall it, you should start with the anaconda-clean
module, which will remove configuration files for when you uninstall Anaconda.
如果您不再使用Anaconda并发现需要卸载它,则应从anaconda-clean
模块开始,该模块将在您卸载Anaconda时删除配置文件。
- conda install anaconda-clean conda安装Python清洁
Type y
when prompted to do so.
在提示时键入y
。
Once it is installed, you can run the following command. You will be prompted to answer y
before deleting each one. If you would prefer not to be prompted, add --yes
to the end of your command:
安装完成后,您可以运行以下命令。 删除每一个之前,系统将提示您回答y
。 如果您不想被提示,请在命令末尾添加--yes
:
anaconda-clean
This will also create a backup folder called .anaconda_backup
in your home directory:
这还将在您的主目录中创建一个名为.anaconda_backup
的备份文件夹:
Output
Backup directory: /home/sammy/.anaconda_backup/2018-05-23T213826
You can now remove your entire Anaconda directory by entering the following command:
现在,您可以通过输入以下命令来删除整个Anaconda目录:
- rm -rf ~/anaconda3 rm -rf〜/ anaconda3
Finally, you can remove the PATH line from your .bashrc
file that Anaconda added. To do so, first open a text editor such as nano:
最后,您可以从Anaconda添加的.bashrc
文件中删除PATH行。 为此,首先打开一个文本编辑器,例如nano:
- nano ~/.bashrc 纳米〜/ .bashrc
Then scroll down to the end of the file (if this is a recent install) or type CTRL + W
to search for Anaconda. Delete or comment out the export PATH
line:
然后向下滚动到文件的末尾(如果这是最近安装的)或键入CTRL + W
搜索Anaconda。 删除或注释export PATH
行:
...
# added by Anaconda3 installer
export PATH="/home/sammy/anaconda3/bin:$PATH"
When you’re done editing the file, type CTRL + X
to exit and y
to save changes.
编辑完文件后,请按CTRL + X
退出并按y
保存更改。
Anaconda is now removed from your server.
Anaconda现在已从服务器中删除。
结论 (Conclusion)
This tutorial walked you through the installation of Anaconda, working with the conda
command-line utility, setting up environments, updating Anaconda, and deleting Anaconda if you no longer need it.
本教程向您介绍了Anaconda的安装,使用conda
命令行实用程序,设置环境,更新Anaconda以及在不再需要时删除Anaconda的过程。
You can use Anaconda to help you manage workloads for data science, scientific computing, analytics, and large-scale data processing. From here, you can check out our tutorials on data analysis and machine learning to learn more about various tools available to use and projects that you can do.
您可以使用Anaconda帮助您管理数据科学,科学计算,分析和大规模数据处理的工作负载。 从这里,您可以查看我们有关数据分析和机器学习的教程,以了解有关各种可用工具和可以执行的项目的更多信息。