如何在Ubuntu 20.04上安装Anaconda Python发行版

介绍 (Introduction)

Anaconda is an open-source package manager, environment manager, and distribution of the Python and R programming languages. It is commonly used for data science, machine learning, 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 20.04 server.

本教程将指导您在Ubuntu 20.04服务器上安装Python 3版本的Anaconda。

先决条件 (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 20.04 initial server setup guide.

您可以通过完成我们的Ubuntu 20.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 2020.02, but you should use a later stable version if it is available.

Anaconda下载页面中找到适用于Python 3的最新版本的Anaconda。 在撰写本文时,最新版本为2020.02,但如果可用,则应使用更高的稳定版本。

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. We’ll output this to a file called anaconda.sh for quicker use.

使用curl下载您从Anaconda网站复制的链接。 我们将其输出到一个名为anaconda.sh的文件中,以加快使用速度。

  • curl https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh --output anaconda.sh

    卷曲https://repo.anaconda.com/archive/Anaconda3- 2020.02 -Linux-x86_64.sh --output anaconda.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 anaconda.sh

    sha256sum anaconda.sh

You’ll receive output that looks similar to this:

您将收到类似于以下内容的输出:


   
   
Output
2b9f088b2022edb474915d9f69a803d6449d5fdb4c303041f60ac4aefcc208bb anaconda.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 3Anaconda上可用的哈希值检查输出,以找到合适的Anaconda版本。 只要您的输出与sha2561行中显示的哈希匹配,就可以了。

Now we can run the script:

现在我们可以运行脚本:

  • bash anaconda.sh

    bash anaconda.sh

You’ll receive the following output:

您将收到以下输出:


   
   
Output
Welcome to Anaconda3 2020.02 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
... Preparing transaction: done Executing transaction: done installation finished. Do you wish the installer to initialize Anaconda3 by running conda init? [yes|no] [no] >>>

Type yes so that you can initialize Anaconda3. You’ll receive some output that states changes made in various directories. One of the lines you receive will thank you for installing Anaconda.

键入yes以便您可以初始化Anaconda3。 您将收到一些输出,指出在各个目录中所做的更改。 您收到的电话之一将感谢您安装Anaconda。


   
   
Output
... Thank you for installing Anaconda3! ...

You can now activate the installation by sourcing the ~/.bashrc file:

现在,您可以通过采购~/.bashrc文件来激活安装:

  • source ~/.bashrc

    来源〜/ .bashrc

Once you have done that, you’ll be placed into the default base programming environment of Anaconda, and your command prompt will change to be the following:

完成此操作后,您将被置于Anaconda的默认base编程环境中,并且命令提示符将变为以下内容:

Although Anaconda ships with this default base programming environment, you should create separate environments for your programs and to keep them isolated from each other.

尽管Anaconda附带了此默认的base编程环境,但您应为程序创建单独的环境并使它们彼此隔离。

You can further 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 _libgcc_mutex 0.1 main alabaster 0.7.12 py37_0 anaconda 2020.02 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.

我们将收到输出,其中包含有关下载了哪些内容以及将要安装哪些软件包的信息,然后提示您继续进行yn 。 只要您同意,请输入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 reflect that you are no longer in the base environment, but in the new one that you just created.

激活环境后,命令提示符前缀将反映您不再处于base环境中,而是处于刚创建的新环境中。

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.8.2

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 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每个环境都将带有几个默认软件包:

  • _libgcc_mutex

    _libgcc_mutex

    _libgcc_mutex

    _libgcc_mutex

  • ca-certificates

    ca-certificates

    ca-certificates

    ca-certificates

  • certifi

    certifi

    certifi

    certifi

  • libedit

    libedit

    libedit

    libedit

  • libffi

    libffi

    libffi

    libffi

  • libgcc-ng

    libgcc-ng

    libgcc-ng

    libgcc-ng

  • libstdcxx-ng

    libstdcxx-ng

    libstdcxx-ng

    libstdcxx-ng

  • ncurses

    ncurses

    ncurses

    ncurses

  • openssl

    openssl

    openssl

    openssl

  • pip

    pip

    pip

    pip

  • python

    python

    python

    python

  • readline

    readline

    readline

    readline

  • setuptools

    setuptools

    setuptools

    setuptools

  • sqlite

    sqlite

    sqlite

    sqlite

  • tk

    tk

    tk

    tk

  • wheel

    wheel

    wheel

    wheel

  • xz

    xz

    xz

    xz

  • zlib

    zlib

    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/2020-05-06T024432

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 this Anaconda block:

然后向下滚动到文件的末尾(如果这是最近安装的)或键入CTRL + W搜索Anaconda。 删除或注释掉这个Anaconda块:

/home/sammy/.bashrc
/home/sammy/.bashrc
...
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/sammy/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/sammy/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/sammy/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/sammy/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

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. If you did not deactivate the base programming environment, you can exit and re-enter the server to remove it.

Anaconda现在已从服务器中删除。 如果您没有停用base编程环境,则可以退出并重新进入服务器以将其删除。

结论 (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帮助您管理数据科学,科学计算,分析和大规模数据处理的工作负载。 从这里,您可以查看我们有关数据分析机器学习的教程,以了解有关各种可用工具和可以执行的项目的更多信息。

We also have a free machine learning ebook available for download, Python Machine Learning Projects.

我们还有免费的机器学习电子书可供下载, Python机器学习项目

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-the-anaconda-python-distribution-on-ubuntu-20-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu 20.04服务器上安装Anaconda,请按照以下步骤进行操作: 1. 首先,你需要下载Anaconda的最新版本。你可以访问Anaconda官方网站(https://www.anaconda.com/products/individual)并下载适用于LinuxAnaconda安装包。 2. 打开终端窗口,并导航到下载的安装包所在的目录。你可以使用以下命令进入下载目录: ``` cd /path/to/download/directory ``` 3. 给Anaconda安装程序添加可执行权限。运行以下命令: ``` chmod +x Anaconda-latest-Linux-x86_64.sh ``` 4. 运行安装程序以开始安装Anaconda。使用以下命令: ``` ./Anaconda-latest-Linux-x86_64.sh ``` 5. 安装程序将提示你接受许可协议。按下Enter键浏览协议,然后按下Enter键以接受协议。 6. 安装程序将提示你选择安装目录。按下Enter键接受默认目录,或根据需要选择其他目录。 7. 安装程序会询问是否将Anaconda添加到系统的PATH中。建议选择“yes”,这样你可以在任何位置运行Anaconda命令。 8. 安装程序将继续安装Anaconda及其相关组件。请等待完成。 9. 安装完成后,你需要关闭并重新打开终端窗口,以便更新系统的环境变量。 10. 验证安装是否成功。在终端中运行以下命令: ``` conda --version ``` 如果你看到输出中显示了Anaconda的版本号,则表示安装成功。 现在,你已经在Ubuntu 20.04服务器上成功安装Anaconda。你可以使用Anaconda来创建和管理Python虚拟环境,以及安装所需的包和库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值