0


Ubuntu22.04 安装Annaconda步骤、conda基础使用和pycharm使用anaconda

概述

  1. 提示:根据用户Ubuntu系统版本存在差异,对比着阅读。

官方软件下载仓库网站
https://repo.anaconda.com/archive/


安装目录


前言

  1. Anaconda简介:

Anaconda就是可以便捷获取包且对包能够进行管理,同时对环境可以统一管理的发行版本。Anaconda包含了conda、Python在内的超过180个科学包及其依赖项。


  1. 提示:以下是本篇文章正文内容,下面安装教程可供参考

一、下载Anaconda package

手动官网下载(不推荐)

Anaconda官网软件下载,无法找到对应链接。这个方法暂时不推荐。

curl下载安装包

STEP 1: Update system repositories

Press “

  1. CTRL+ALT+T

” to open the terminal of your Ubuntu 22.04 and run the below-given command to update system repositories:

  1. $ sudoapt update

STEP 2: Install curl package

In the next step, we will download the “curl” utility as it permits fetching the installation script of Anaconda:

  1. $ sudoaptinstallcurl -y

STEP 3: Prepare Anaconda Installer

Switch to the “**/tmp” directly with the help of the “cd**” command to make it your present working directory:

  1. $ cd /tmp

After that, utilize the following “curl” command for downloading the Anaconda installer script. Also, make sure you download the latest version by firstly visiting their official site[首选最新的Anaconda3-2022.05-Linux-x86_64.sh]:

  1. curl --output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh

Then, match the “SHA-256” checksum of the downloaded Anaconda script with the code displayed on the official site:

  1. ~/tmp sha256sum anaconda.sh
  2. a7c0afe862f6ea19a596801fc138bde0463abcbce1b753e8d5c474b506a2db2d anaconda.sh

STEP 4: Install Anaconda on Ubuntu 22.04

Till this point, we have fulfilled all prerequisites, and our Ubuntu 22.04 is all ready for the installation of Anaconda. To do so, run the downloaded Anaconda installer script:

  1. $ bash anaconda.sh

Upon doing so, the Anaconda installation wizard will appear on the terminal; press “Enter” to continue:

  1. bash anaconda.sh
  2. Welcome to Anaconda3 2022.05
  3. In order to continue the installation process, please review the license
  4. agreement.
  5. Please, press ENTER to continue>>>

Carefully read the Anaconda End User License Agreement:
在这里插入图片描述
After reading the License agreement of Anaconda, type out “yes” to move ahead:

  1. The following packages listed on https://www.anaconda.com/cryptography are included in the repository accessible
  2. through Anaconda Distribution that relate to cryptography.
  3. Last updated February 25, 2022
  4. Do you accept the license terms? [yes|no][no]>>>
  5. Please answer 'yes' or 'no':'
  6. >>>yes
  7. Anaconda3 will now be installed into this location:
  8. /home/xxxx/anaconda3
  9. - Press ENTER to confirm the location
  10. - Press CTRL-C to abort the installation
  11. - Or specify a different location below

Specify the directory location of your Ubuntu 22.04 system where you want to save the files related to the Anaconda installation. In our case, we have selected the “/home/xxxx/anaconda3” directory(直接回车键):

  1. Anaconda3 will now be installed into this location:
  2. /home/xxx/anaconda3
  3. - Press ENTER to confirm the location
  4. - Press CTRL-C to abort the installation
  5. - Or specify a different location below
  6. [/home/xxxx/anaconda3]>>>

Wait for a few minutes as the Anaconda installation will take some time to complete:

  1. Preparing transaction: done
  2. Executing transaction: |
  3. Installed package of scikit-learn can be accelerated using scikit-learn-intelex.
  4. More details are available here: https://intel.github.io/scikit-learn-intelex
  5. For example:
  6. $ conda install scikit-learn-intelex
  7. $ python -m sklearnex my_application.py
  8. done
  9. installation finished.
  10. Do you wish the installer to initialize Anaconda3
  11. by running conda init? [yes|no][no]>>>yes
  12. no change /home/xxxx/anaconda3/condabin/conda
  13. no change /home/xxxx/anaconda3/bin/conda
  14. no change /home/xxxx/anaconda3/bin/conda-env
  15. no change /home/xxxx/anaconda3/bin/activate
  16. no change /home/xxxx/anaconda3/bin/deactivate
  17. no change /home/xxxx/anaconda3/etc/profile.d/conda.sh
  18. no change /home/xxxx/anaconda3/etc/fish/conf.d/conda.fish
  19. no change /home/xxxx/anaconda3/shell/condabin/Conda.psm1
  20. no change /home/xxxx/anaconda3/shell/condabin/conda-hook.ps1
  21. no change /home/xxxx/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
  22. no change /home/xxxx/anaconda3/etc/profile.d/conda.csh
  23. modified /home/xxxx/.zshrc

The below-given output signifies that we have successfully installed Anaconda on Ubuntu 22.04:

  1. ==> For changes to take effect, close and re-open your current shell. <==
  2. If you'd prefer that conda's base environment not be activated on startup,
  3. set the auto_activate_base parameter to false:
  4. conda config --set auto_activate_base false
  5. Thank you for installing Anaconda3!===========================================================================
  6. Working with Python and Jupyter is a breeze in DataSpell. It is an IDE
  7. designed for exploratory data analysis and ML. Get better data insights
  8. with DataSpell.
  9. DataSpell for Anaconda is available at: https://www.anaconda.com/dataspell

PS:

  1. For changes to take effect, close and re-open your current shell.

关闭当前命令行,并重新打开,刚刚安装和初始化Anaconda设置才可以生效。

重新打开一个命令行(terminal)直接就进入了conda的base环境,如下:

  1. (bash)/home/xxxx:$
  1. If you'd prefer that conda's base environment not be activated on startup, set the auto_activate_base parameter to false:

如果您希望 conda 的基础环境在启动时不被激活,请将 auto_activate_base 参数设置为 false

设置命令如下:

  1. conda config --set auto_activate_base false

当然以上的一条命令执行完毕后,依旧需要重启一下命令行才能生效。想要再次进入conda的base基础环境,只需要使用对应的conda指令即可。
命令如下:

  1. conda activate base

STEP 5: Activate the Environment settings

After installing Anaconda, the next step is to activate the added environment settings in the “**.bashrc or .zshrc**” file by executing the following command:

  1. 使用默认shell:
  1. # 默认是bash配置文件
  2. $ source ~/.bashrc
  1. 使用zsh:
  1. # 如果更换成了zsh配置文件
  2. $ source ~/.zshrc

STEP 6: Verify the Anaconda installation

Lastly, execute the below-given “conda” command to verify if Anaconda is working on your Ubuntu 22.04 system:

  1. $ conda list
  2. packages in environment at /home/xxxx/anaconda3:
  3. ## Name Version Build Channel
  4. _ipyw_jlab_nb_ext_conf 0.1.0 py39h06a4308_1
  5. _libgcc_mutex 0.1 main
  6. _openmp_mutex 4.5 1_gnu
  7. aiohttp 3.8.1 py39h7f8727e_1
  8. aiosignal 1.2.0 pyhd3eb1b0_0
  9. alabaster 0.7.12 pyhd3eb1b0_0
  10. anaconda 2022.05 py39_0
  11. anaconda-client 1.9.0 py39h06a4308_0
  12. anaconda-navigator 2.1.4 py39h06a4308_0
  13. anaconda-project 0.10.2 pyhd3eb1b0_0
  14. anyio 3.5.0 py39h06a4308_0
  15. appdirs 1.4.4 pyhd3eb1b0_0
  16. argon2-cffi 21.3.0 pyhd3eb1b0_0
  17. argon2-cffi-bindings 21.2.0 py39h7f8727e_0
  18. arrow 1.2.2 pyhd3eb1b0_0
  19. astroid 2.6.6 py39h06a4308_0
  20. astropy 5.0.4 py39hce1f21e_0
  21. asttokens 2.0.5 pyhd3eb1b0_0

Or check out the installed version of Anaconda by typing out “conda” command with the “–version” option:

  1. $ conda --version

As you can see from the given output, we have “conda 4.5.11” installed on our Ubuntu 22.04:

  1. (base) conda --version
  2. conda 4.12.0

How to remove Anaconda from Ubuntu 22.04

In the terminal, you can write out the following command to remove Anaconda from your system:

  1. $ rm -rf ~/anaconda3

We have provided the basic method to install Anaconda on Ubuntu 22.04. After installation, you can explore this platform as required.

Conclusion

To install Anaconda in Ubuntu 22.04, download the Anaconda installer file with the “

  1. $ curl output anaconda.sh https://repo.anaconda.com/archive/Anaconda3-5.3.1-Linux-x86_64.sh

” command, then install the “bash anaconda.sh” script and verify using “

  1. conda list

” or “

  1. conda version

” commands. This write-up discussed the procedure of installing Anaconda on Ubuntu 22.04. Give it a try and step into the world of data science learning.


二、conda的基础使用

1.环境管理

代码如下(示例):

  1. # 1.查看conda的版本号
  2. conda --version
  3. # 2.查看虚拟环境列表
  4. conda info --envs
  5. # 3.创建虚拟环境并指定python的版本号为3.8
  6. conda create -n virtualname pip python=3.9# 4.激活虚拟环境
  7. conda activate virtualname
  8. # 5.退出虚拟环境
  9. conda deactivate
  10. # 6.删除虚拟环境
  11. conda remove --name virtualname --all

2.包管理

代码如下(示例):

  1. # 1.安装包
  2. conda install PackageName
  3. # 2.安装多个包
  4. conda install name1 name2 ...
  5. # 3.安装包并指定版本号
  6. conda installPackageName=版本号
  7. # 4.卸载包
  8. conda remove PackageName
  9. # 5.更新包
  10. conda update PackageName
  11. # 6.更新环境中的所有包
  12. conda update --all
  13. # 7.列出已安装的包
  14. conda list
  15. # 8.搜寻包
  16. conda search PackageName

三、pycharm使用anaconda环境

STEP 1: 创建新的环境

  1. conda create --name <env_name><package_names>

<env_name> 即创建的环境名。建议以英文命名,且不加空格,名称两边不加尖括号“<>”
<package_names> 即安装在环境中的包名。名称两边不加尖括号“<>”


① 如果要安装指定的版本号,则只需要在包名后面以 python=3.9 和版本号的形式执行。
如:

  1. conda create --name python2 python=2.7

,即创建一个名为“pytorch”的环境,环境中安装版本为2.7的python。
② 如果要在新创建的环境中创建多个包,则直接在 <package_names> 后以空格隔开,添加多个包名即可。
如:

  1. conda create -n python3 python=3.5 numpy pandas

,即创建一个名为“pytorch”的环境,环境中安装版本为3.5的python,同时也安装了numpy和pandas库。

  1. --name

同样可以替换为 -n


在命令行中输入下列指令创建虚拟环境:

  1. conda create -n pytorch1.12 python==3.9

其中 pytorch为本次创建的虚拟环境的名称,1.12为创建的pytorch虚拟环境的版本:

  1. Collecting package metadata (current_repodata.json): done
  2. Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
  3. Collecting package metadata (repodata.json): done
  4. Solving environment: done==> WARNING: A newer version of conda exists. <==
  5. current version: 4.12.0
  6. latest version: 22.9.0
  7. Please update conda by running
  8. $ conda update -n base -c defaults conda
  9. ## Package Plan ##
  10. environment location: /home/xxxx/anaconda3/envs/pytorch
  11. added / updated specs:
  12. - numpy
  13. - python==3.9
  14. The following packages will be downloaded:
  15. package | build
  16. ---------------------------|-----------------
  17. _openmp_mutex-5.1 | 1_gnu 21 KB
  18. ca-certificates-2022.07.19 | h06a4308_0 124 KB
  19. certifi-2022.9.24 | py39h06a4308_0 154 KB
  20. ld_impl_linux-64-2.38 | h1181459_1 654 KB
  21. libgcc-ng-11.2.0 | h1234567_1 5.3 MB
  22. libgomp-11.2.0 | h1234567_1 474 KB
  23. libstdcxx-ng-11.2.0 | h1234567_1 4.7 MB
  24. ncurses-6.3 | h5eee18b_3 781 KB
  25. numpy-1.23.1 | py39h6c91a56_0 11 KB
  26. numpy-base-1.23.1 | py39ha15fc14_0 5.6 MB
  27. openssl-1.1.1q | h7f8727e_0 2.5 MB
  28. pip-22.2.2 | py39h06a4308_0 2.3 MB
  29. python-3.9.0 | hdb3f193_2 18.1 MB
  30. setuptools-63.4.1 | py39h06a4308_0 1.1 MB
  31. sqlite-3.39.3 | h5082296_0 1.1 MB
  32. tk-8.6.12 | h1ccaba5_0 3.0 MB
  33. tzdata-2022c | h04d1e81_0 107 KB
  34. xz-5.2.6 | h5eee18b_0 394 KB
  35. zlib-1.2.12 | h5eee18b_3 103 KB
  36. ------------------------------------------------------------
  37. Total: 46.5 MB
  38. Proceed ([y]/n)? y
  39. Downloading and Extracting Packages
  40. tzdata-2022c |107 KB |################################################################################################################################################################# | 100%
  41. numpy-base-1.23.1 |5.6 MB |################################################################################################################################################################# | 100%
  42. zlib-1.2.12 |103 KB |################################################################################################################################################################# | 100%
  43. _openmp_mutex-5.1 |21 KB |################################################################################################################################################################# | 100%
  44. python-3.9.0 |18.1 MB |################################################################################################################################################################# | 100%
  45. sqlite-3.39.3 |1.1 MB |################################################################################################################################################################# | 100%
  46. libgcc-ng-11.2.0 |5.3 MB |################################################################################################################################################################# | 100%
  47. pip-22.2.2 |2.3 MB |################################################################################################################################################################# | 100%
  48. tk-8.6.12 |3.0 MB |################################################################################################################################################################# | 100%
  49. ncurses-6.3 |781 KB |################################################################################################################################################################# | 100%
  50. xz-5.2.6 |394 KB |################################################################################################################################################################# | 100%
  51. numpy-1.23.1 |11 KB |################################################################################################################################################################# | 100%
  52. libstdcxx-ng-11.2.0 |4.7 MB |################################################################################################################################################################# | 100%
  53. libgomp-11.2.0 |474 KB |################################################################################################################################################################# | 100%
  54. setuptools-63.4.1 |1.1 MB |################################################################################################################################################################# | 100%
  55. ld_impl_linux-64-2.3 |654 KB |################################################################################################################################################################# | 100%
  56. ca-certificates-2022 |124 KB |################################################################################################################################################################# | 100%
  57. certifi-2022.9.24 |154 KB |################################################################################################################################################################# | 100%
  58. openssl-1.1.1q |2.5 MB |################################################################################################################################################################# | 100%
  59. Preparing transaction: done
  60. Verifying transaction: done
  61. Executing transaction: done## To activate this environment, use## $ conda activate pytorch## To deactivate an active environment, use## $ conda deactivate

STEP 2: 安装结束之后输入下列指令激活虚拟环境

  1. conda activate pytorch

创建完成后,在Anaconda的安装目录的envs文件夹下,会生成刚刚创建的虚拟环境名称的文件夹。

STEP 3: 设置pycharm

然后我们打开pycharm,选择对应的conda环境。

  • 选择‘’Add new Interpreter”添加刚才建立的虚拟环境。
  • 选择“conda environment”,点击“Interpreter”,填写“/home/xxxx/anaconda3/env/bin/python3.9
标签: pycharm conda python

本文转载自: https://blog.csdn.net/aiboom/article/details/127324633
版权归原作者 心儿痒痒 所有, 如有侵权,请联系我们删除。

“Ubuntu22.04 安装Annaconda步骤、conda基础使用和pycharm使用anaconda”的评论:

还没有评论