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

本文主要是介绍Ubuntu22.04 安装Annaconda步骤、conda基础使用和pycharm使用anaconda,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

概述

提示:根据用户Ubuntu系统版本存在差异,对比着阅读。
官方软件下载仓库网站
https://repo.anaconda.com/archive/


安装目录

  • 概述
  • 前言
  • 一、下载Anaconda package
    • 手动官网下载(不推荐)
    • curl下载安装包
      • STEP 1: Update system repositories
      • STEP 2: Install curl package
      • STEP 3: Prepare Anaconda Installer
      • STEP 4: Install Anaconda on Ubuntu 22.04
      • STEP 5: Activate the Environment settings
      • STEP 6: Verify the Anaconda installation
      • How to remove Anaconda from Ubuntu 22.04
      • Conclusion
  • 二、conda的基础使用
    • 1.环境管理
    • 2.包管理
  • 三、pycharm使用anaconda环境
    • STEP 1: 创建新的环境
    • STEP 2: 安装结束之后输入下列指令激活虚拟环境
    • STEP 3: 设置pycharm


前言

Anaconda简介:

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


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

一、下载Anaconda package

手动官网下载(不推荐)

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

curl下载安装包

STEP 1: Update system repositories

Press “CTRL+ALT+T” to open the terminal of your Ubuntu 22.04 and run the below-given command to update system repositories:

$ sudo apt 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:

$ sudo apt install curl -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:

$ 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]:

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:

~/tmp sha256sum anaconda.sh                                              
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:

$ bash anaconda.sh

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

bash anaconda.sh         Welcome to Anaconda3 2022.05In order to continue the installation process, please review the license
agreement.
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:

The following packages listed on https://www.anaconda.com/cryptography are included in the repository accessible 
through Anaconda Distribution that relate to cryptography.Last updated February 25, 2022Do you accept the license terms? [yes|no]
[no] >>> 
Please answer 'yes' or 'no':'
>>> yesAnaconda3 will now be installed into this location:
/home/xxxx/anaconda3- Press ENTER to confirm the location- Press CTRL-C to abort the installation- 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(直接回车键):

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

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

Preparing transaction: done
Executing transaction: | Installed package of scikit-learn can be accelerated using scikit-learn-intelex.More details are available here: https://intel.github.io/scikit-learn-intelexFor example:$ conda install scikit-learn-intelex$ python -m sklearnex my_application.pydone
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>> yes
no change     /home/xxxx/anaconda3/condabin/conda
no change     /home/xxxx/anaconda3/bin/conda
no change     /home/xxxx/anaconda3/bin/conda-env
no change     /home/xxxx/anaconda3/bin/activate
no change     /home/xxxx/anaconda3/bin/deactivate
no change     /home/xxxx/anaconda3/etc/profile.d/conda.sh
no change     /home/xxxx/anaconda3/etc/fish/conf.d/conda.fish
no change     /home/xxxx/anaconda3/shell/condabin/Conda.psm1
no change     /home/xxxx/anaconda3/shell/condabin/conda-hook.ps1
no change     /home/xxxx/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
no change     /home/xxxx/anaconda3/etc/profile.d/conda.csh
modified      /home/xxxx/.zshrc

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

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

PS:

For changes to take effect, close and re-open your current shell.
关闭当前命令行,并重新打开,刚刚安装和初始化Anaconda设置才可以生效。

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

(bash)/home/xxxx:$ 

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

设置命令如下:

conda config --set auto_activate_base false

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

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:
使用默认shell:

# 默认是bash配置文件
$ source ~/.bashrc

使用zsh:

# 如果更换成了zsh配置文件
$ 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:

$ conda listpackages in environment at /home/xxxx/anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0            py39h06a4308_1  
_libgcc_mutex             0.1                        main  
_openmp_mutex             4.5                       1_gnu  
aiohttp                   3.8.1            py39h7f8727e_1  
aiosignal                 1.2.0              pyhd3eb1b0_0  
alabaster                 0.7.12             pyhd3eb1b0_0  
anaconda                  2022.05                  py39_0  
anaconda-client           1.9.0            py39h06a4308_0  
anaconda-navigator        2.1.4            py39h06a4308_0  
anaconda-project          0.10.2             pyhd3eb1b0_0  
anyio                     3.5.0            py39h06a4308_0  
appdirs                   1.4.4              pyhd3eb1b0_0  
argon2-cffi               21.3.0             pyhd3eb1b0_0  
argon2-cffi-bindings      21.2.0           py39h7f8727e_0  
arrow                     1.2.2              pyhd3eb1b0_0  
astroid                   2.6.6            py39h06a4308_0  
astropy                   5.0.4            py39hce1f21e_0  
asttokens                 2.0.5              pyhd3eb1b0_0  

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

$ conda --version

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

(base) conda --version                       
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:

$ 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 “$ 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 “conda list” or “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.查看conda的版本号
conda --version
# 2.查看虚拟环境列表
conda info --envs
# 3.创建虚拟环境并指定python的版本号为3.8
conda create -n virtualname pip python=3.9
# 4.激活虚拟环境
conda activate virtualname
# 5.退出虚拟环境
conda deactivate
# 6.删除虚拟环境
conda remove --name virtualname --all

2.包管理

代码如下(示例):

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

三、pycharm使用anaconda环境

STEP 1: 创建新的环境

conda create --name <env_name> <package_names>

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


① 如果要安装指定的版本号,则只需要在包名后面以 python=3.9 和版本号的形式执行。
如: conda create --name python2 python=2.7,即创建一个名为“pytorch”的环境,环境中安装版本为2.7的python。
② 如果要在新创建的环境中创建多个包,则直接在 <package_names> 后以空格隔开,添加多个包名即可。
如: conda create -n python3 python=3.5 numpy pandas ,即创建一个名为“pytorch”的环境,环境中安装版本为3.5的python,同时也安装了numpy和pandas库。
--name 同样可以替换为 -n


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

conda create -n pytorch1.12  python==3.9

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

Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done==> WARNING: A newer version of conda exists. <==current version: 4.12.0latest version: 22.9.0Please update conda by running$ conda update -n base -c defaults conda## Package Plan ##environment location: /home/xxxx/anaconda3/envs/pytorchadded / updated specs:- numpy- python==3.9The following packages will be downloaded:package                    |            build---------------------------|-----------------_openmp_mutex-5.1          |            1_gnu          21 KBca-certificates-2022.07.19 |       h06a4308_0         124 KBcertifi-2022.9.24          |   py39h06a4308_0         154 KBld_impl_linux-64-2.38      |       h1181459_1         654 KBlibgcc-ng-11.2.0           |       h1234567_1         5.3 MBlibgomp-11.2.0             |       h1234567_1         474 KBlibstdcxx-ng-11.2.0        |       h1234567_1         4.7 MBncurses-6.3                |       h5eee18b_3         781 KBnumpy-1.23.1               |   py39h6c91a56_0          11 KBnumpy-base-1.23.1          |   py39ha15fc14_0         5.6 MBopenssl-1.1.1q             |       h7f8727e_0         2.5 MBpip-22.2.2                 |   py39h06a4308_0         2.3 MBpython-3.9.0               |       hdb3f193_2        18.1 MBsetuptools-63.4.1          |   py39h06a4308_0         1.1 MBsqlite-3.39.3              |       h5082296_0         1.1 MBtk-8.6.12                  |       h1ccaba5_0         3.0 MBtzdata-2022c               |       h04d1e81_0         107 KBxz-5.2.6                   |       h5eee18b_0         394 KBzlib-1.2.12                |       h5eee18b_3         103 KB------------------------------------------------------------Total:        46.5 MB
Proceed ([y]/n)? yDownloading and Extracting Packages
tzdata-2022c         | 107 KB    | ################################################################################################################################################################# | 100% 
numpy-base-1.23.1    | 5.6 MB    | ################################################################################################################################################################# | 100% 
zlib-1.2.12          | 103 KB    | ################################################################################################################################################################# | 100% 
_openmp_mutex-5.1    | 21 KB     | ################################################################################################################################################################# | 100% 
python-3.9.0         | 18.1 MB   | ################################################################################################################################################################# | 100% 
sqlite-3.39.3        | 1.1 MB    | ################################################################################################################################################################# | 100% 
libgcc-ng-11.2.0     | 5.3 MB    | ################################################################################################################################################################# | 100% 
pip-22.2.2           | 2.3 MB    | ################################################################################################################################################################# | 100% 
tk-8.6.12            | 3.0 MB    | ################################################################################################################################################################# | 100% 
ncurses-6.3          | 781 KB    | ################################################################################################################################################################# | 100% 
xz-5.2.6             | 394 KB    | ################################################################################################################################################################# | 100% 
numpy-1.23.1         | 11 KB     | ################################################################################################################################################################# | 100% 
libstdcxx-ng-11.2.0  | 4.7 MB    | ################################################################################################################################################################# | 100% 
libgomp-11.2.0       | 474 KB    | ################################################################################################################################################################# | 100% 
setuptools-63.4.1    | 1.1 MB    | ################################################################################################################################################################# | 100% 
ld_impl_linux-64-2.3 | 654 KB    | ################################################################################################################################################################# | 100% 
ca-certificates-2022 | 124 KB    | ################################################################################################################################################################# | 100% 
certifi-2022.9.24    | 154 KB    | ################################################################################################################################################################# | 100% 
openssl-1.1.1q       | 2.5 MB    | ################################################################################################################################################################# | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate pytorch
#
# To deactivate an active environment, use
#
#     $ conda deactivate

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

conda activate pytorch

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

STEP 3: 设置pycharm

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

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

这篇关于Ubuntu22.04 安装Annaconda步骤、conda基础使用和pycharm使用anaconda的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/334098

相关文章

Java使用Javassist动态生成HelloWorld类

《Java使用Javassist动态生成HelloWorld类》Javassist是一个非常强大的字节码操作和定义库,它允许开发者在运行时创建新的类或者修改现有的类,本文将简单介绍如何使用Javass... 目录1. Javassist简介2. 环境准备3. 动态生成HelloWorld类3.1 创建CtC

使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Java使用jar命令配置服务器端口的完整指南

《Java使用jar命令配置服务器端口的完整指南》本文将详细介绍如何使用java-jar命令启动应用,并重点讲解如何配置服务器端口,同时提供一个实用的Web工具来简化这一过程,希望对大家有所帮助... 目录1. Java Jar文件简介1.1 什么是Jar文件1.2 创建可执行Jar文件2. 使用java

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

Java中的抽象类与abstract 关键字使用详解

《Java中的抽象类与abstract关键字使用详解》:本文主要介绍Java中的抽象类与abstract关键字使用详解,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、抽象类的概念二、使用 abstract2.1 修饰类 => 抽象类2.2 修饰方法 => 抽象方法,没有

MyBatis ParameterHandler的具体使用

《MyBatisParameterHandler的具体使用》本文主要介绍了MyBatisParameterHandler的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录一、概述二、源码1 关键属性2.setParameters3.TypeHandler1.TypeHa

Spring 中的切面与事务结合使用完整示例

《Spring中的切面与事务结合使用完整示例》本文给大家介绍Spring中的切面与事务结合使用完整示例,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录 一、前置知识:Spring AOP 与 事务的关系 事务本质上就是一个“切面”二、核心组件三、完

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

使用Python实现Word文档的自动化对比方案

《使用Python实现Word文档的自动化对比方案》我们经常需要比较两个Word文档的版本差异,无论是合同修订、论文修改还是代码文档更新,人工比对不仅效率低下,还容易遗漏关键改动,下面通过一个实际案例... 目录引言一、使用python-docx库解析文档结构二、使用difflib进行差异比对三、高级对比方

详解python pycharm与cmd中制表符不一样

《详解pythonpycharm与cmd中制表符不一样》本文主要介绍了pythonpycharm与cmd中制表符不一样,这个问题通常是因为PyCharm和命令行(CMD)使用的制表符(tab)的宽... 这个问题通常是因为PyCharm和命令行(CMD)使用的制表符(tab)的宽度不同导致的。在PyChar