How to use conda in Ubuntu 22.04

How to use conda in Ubuntu 22.04

切换清华源

bash 复制代码
sudo tee ~/.condarc <<-'EOF'
auto_activate_base: false

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
EOF

创建环境

bash 复制代码
lwk@qwfys:~$ conda create -n harbin
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/lwk/anaconda3/envs/harbin



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate harbin
#
# To deactivate an active environment, use
#
#     $ conda deactivate

lwk@qwfys:~$

查看环境

bash 复制代码
lwk@qwfys:~$ conda info --envs
# conda environments:
#
base                     /home/lwk/anaconda3
harbin                   /home/lwk/anaconda3/envs/harbin
shaoxing                 /home/lwk/anaconda3/envs/shaoxing

lwk@qwfys:~$

激活环境

bash 复制代码
lwk@qwfys:~$ conda activate harbin
(harbin) lwk@qwfys:~$

查看环境中的包

bash 复制代码
(harbin) lwk@qwfys:~$ conda list
# packages in environment at /home/lwk/anaconda3/envs/harbin:
#
# Name                    Version                   Build  Channel
(harbin) lwk@qwfys:~$
bash 复制代码
(harbin) lwk@qwfys:~$ pip list
Package                   Version
------------------------- ----------------
anyio                     4.2.0
apt-clone                 0.2.1
apturl                    0.5.2
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 2.4.1
async-lru                 2.0.4
async-timeout             4.0.1
attrs                     23.2.0
Babel                     2.14.0
beautifulsoup4            4.10.0
bleach                    6.1.0
blinker                   1.4
Brlapi                    0.8.3
Brotli                    1.0.9
certifi                   2020.6.20
cffi                      1.16.0
chardet                   4.0.0
charset-normalizer        3.3.2
click                     8.0.3
colorama                  0.4.4
comm                      0.2.1
command-not-found         0.3
configobj                 5.0.6
cryptography              3.4.8
cupshelpers               1.0
dbus-python               1.2.18
debugpy                   1.8.0
decorator                 5.1.1
defer                     1.0.6
defusedxml                0.7.1
distro                    1.7.0
exceptiongroup            1.2.0
executing                 2.0.1
eyeD3                     0.8.10
fastjsonschema            2.19.1
filelock                  3.6.0
fqdn                      1.5.1
httplib2                  0.20.2
idna                      3.3
ifaddr                    0.1.7
IMDbPY                    2021.4.18
importlib-metadata        4.6.4
inflection                0.5.1
ipykernel                 6.29.0
ipython                   8.20.0
isoduration               20.11.0
jedi                      0.19.1
jeepney                   0.7.1
Jinja2                    3.1.3
json5                     0.9.14
jsonpointer               2.4
jsonschema                4.21.1
jsonschema-specifications 2023.12.1
jupyter_client            8.6.0
jupyter_core              5.7.1
jupyter-events            0.9.0
jupyter-lsp               2.2.2
jupyter_server            2.12.5
jupyter_server_terminals  0.5.2
jupyterlab                4.0.11
jupyterlab_pygments       0.3.0
jupyterlab_server         2.25.2
keyring                   23.5.0
launchpadlib              1.10.16
lazr.restfulclient        0.14.4
lazr.uri                  1.0.6
louis                     3.20.0
macaroonbakery            1.3.1
Mako                      1.1.3
MarkupSafe                2.0.1
matplotlib-inline         0.1.6
mistune                   3.0.2
more-itertools            8.10.0
mutagen                   1.45.1
nbclient                  0.9.0
nbconvert                 7.14.2
nbformat                  5.9.2
nemo-emblems              6.0.1
nest-asyncio              1.6.0
netaddr                   0.8.0
netifaces                 0.11.0
notebook_shim             0.2.3
oauthlib                  3.2.0
onboard                   1.4.1
openapi                   1.1.0
overrides                 7.7.0
packaging                 21.3
PAM                       0.4.2
pandocfilters             1.5.1
parso                     0.8.3
pexpect                   4.8.0
Pillow                    9.0.1
pip                       22.0.2
platformdirs              4.1.0
prometheus-client         0.19.0
prompt-toolkit            3.0.43
protobuf                  3.12.4
psutil                    5.9.0
ptyprocess                0.7.0
pure-eval                 0.2.2
pycairo                   1.20.1
pycparser                 2.21
pycryptodomex             3.11.0
pycups                    2.0.1
pycurl                    7.44.1
pyelftools                0.27
Pygments                  2.17.2
PyGObject                 3.42.1
PyICU                     2.8.1
pyinotify                 0.9.6
PyJWT                     2.3.0
pymacaroons               0.13.0
PyNaCl                    1.5.0
pyparsing                 2.4.7
pyparted                  3.11.7
pyRFC3339                 1.1
python-apt                2.4.0+ubuntu3
python-dateutil           2.8.2
python-debian             0.1.43+ubuntu1.1
python-gnupg              0.4.8
python-json-logger        2.0.7
python-magic              0.4.24
python-xlib               0.29
pytz                      2022.1
pyxdg                     0.27
PyYAML                    5.4.1
pyzmq                     25.1.2
qrcode                    7.3.1
referencing               0.33.0
reportlab                 3.6.8
requests                  2.31.0
requests-file             1.5.1
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.17.1
screen-resolution-extra   0.0.0
SecretStorage             3.3.1
Send2Trash                1.8.2
setproctitle              1.2.2
setuptools                59.6.0
six                       1.16.0
sniffio                   1.3.0
soupsieve                 2.3.1
stack-data                0.6.3
systemd-python            234
terminado                 0.18.0
tinycss2                  1.1.1
tldextract                3.1.2
tomli                     2.0.1
tornado                   6.4
traitlets                 5.14.1
types-python-dateutil     2.8.19.20240106
typing_extensions         4.9.0
ubuntu-drivers-common     0.0.0
ufw                       0.36.1
Unidecode                 1.3.3
uri-template              1.3.0
urllib3                   1.26.5
vboxapi                   1.0
wadllib                   1.3.6
wcwidth                   0.2.13
webcolors                 1.13
webencodings              0.5.1
websocket-client          1.7.0
websockets                9.1
wheel                     0.37.1
xdg                       5
xkit                      0.0.0
xlrd                      1.2.0
yt-dlp                    2022.4.8
zipp                      1.0.0
(harbin) lwk@qwfys:~$

在环境中安装包

bash 复制代码
(harbin) lwk@qwfys:~$ conda install openpyxl                                                                                                                                                  
Collecting package metadata (current_repodata.json): done                                                                                                                                     
Solving environment: done                                                                                                                                                                     
                                                                                                                                                                                              
## Package Plan ##                                                                                                                                                                            
                                                                                                                                                                                              
  environment location: /home/lwk/anaconda3/envs/harbin                                                                                                                                       
                                                                                                                                                                                              
  added / updated specs:                                                                                                                                                                      
    - openpyxl                                                                                                                                                                                
                                                                                                                                                                                              
                                                                                                                                                                                              
The following packages will be downloaded:                                                                                                                                                    
                                                                                                                                                                                              
    package                    |            build                                                                                                                                             
    ---------------------------|-----------------                                                                                                                                             
    et_xmlfile-1.1.0           |  py312h06a4308_1          12 KB  defaults
    openpyxl-3.0.10            |  py312h5eee18b_0         647 KB  defaults
    pandas-2.1.4               |  py312h526ad5a_0        14.7 MB  defaults
    ------------------------------------------------------------
                                           Total:        15.3 MB

The following NEW packages will be INSTALLED:

  et_xmlfile         anaconda/pkgs/main/linux-64::et_xmlfile-1.1.0-py312h06a4308_1 
  openpyxl           anaconda/pkgs/main/linux-64::openpyxl-3.0.10-py312h5eee18b_0 

The following packages will be DOWNGRADED:

  pandas                              2.2.1-py312h526ad5a_0 --> 2.1.4-py312h526ad5a_0 


Proceed ([y]/n)? y


Downloading and Extracting Packages
                                                                                                                                                                                              
Preparing transaction: done                                                                                                                                                                   
Verifying transaction: done                                                                                                                                                                   
Executing transaction: done
(harbin) lwk@qwfys:~$

退出当前环境

bash 复制代码
(harbin) lwk@qwfys:~$ conda deactivate
lwk@qwfys:~$

命令行自动补全

bash 复制代码
conda install -c conda-forge conda-bash-completion

具体安装过程如下:

bash 复制代码
lwk@qwfys:~$ conda install -c conda-forge conda-bash-completion
Channels:
 - conda-forge
 - defaults
 - https://repo.anaconda.com/pkgs/main
Platform: linux-64
Collecting package metadata (repodata.json): \done
Solving environment: done

## Package Plan ##

  environment location: /home/lwk/miniconda3

  added / updated specs:
    - conda-bash-completion


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _libgcc_mutex-0.1          |      conda_forge           3 KB  conda-forge
    _openmp_mutex-4.5          |            2_gnu          23 KB  conda-forge
    bash-completion-2.11       |       ha770c72_1         205 KB  conda-forge
    ca-certificates-2024.2.2   |       hbcca054_0         152 KB  conda-forge
    certifi-2024.2.2           |     pyhd8ed1ab_0         157 KB  conda-forge
    conda-24.1.2               |  py312h7900ff3_0         1.2 MB  conda-forge
    conda-bash-completion-1.7  |       ha770c72_1          21 KB  conda-forge
    libexpat-2.5.0             |       hcb278e6_1          76 KB  conda-forge
    libgcc-ng-13.2.0           |       h807b86a_5         752 KB  conda-forge
    libgomp-13.2.0             |       h807b86a_5         410 KB  conda-forge
    libnsl-2.0.1               |       hd590300_0          33 KB  conda-forge
    libsqlite-3.45.1           |       h2797004_0         839 KB  conda-forge
    libuuid-2.38.1             |       h0b41bf4_0          33 KB  conda-forge
    libxcrypt-4.4.36           |       hd590300_1          98 KB  conda-forge
    libzlib-1.2.13             |       hd590300_5          60 KB  conda-forge
    openssl-3.2.1              |       hd590300_0         2.7 MB  conda-forge
    python-3.12.2              |hab00c5b_0_cpython        30.8 MB  conda-forge
    python_abi-3.12            |          4_cp312           6 KB  conda-forge
    tk-8.6.13                  |noxft_h4845f30_101         3.2 MB  conda-forge
    zlib-1.2.13                |       hd590300_5          91 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        40.8 MB

The following NEW packages will be INSTALLED:

  bash-completion    conda-forge/linux-64::bash-completion-2.11-ha770c72_1 
  conda-bash-comple~ conda-forge/linux-64::conda-bash-completion-1.7-ha770c72_1 
  libexpat           conda-forge/linux-64::libexpat-2.5.0-hcb278e6_1 
  libnsl             conda-forge/linux-64::libnsl-2.0.1-hd590300_0 
  libsqlite          conda-forge/linux-64::libsqlite-3.45.1-h2797004_0 
  libxcrypt          conda-forge/linux-64::libxcrypt-4.4.36-hd590300_1 
  libzlib            conda-forge/linux-64::libzlib-1.2.13-hd590300_5 
  python_abi         conda-forge/linux-64::python_abi-3.12-4_cp312 

The following packages will be UPDATED:

  ca-certificates    pkgs/main::ca-certificates-2023.12.12~ --> conda-forge::ca-certificates-2024.2.2-hbcca054_0 
  libgcc-ng          pkgs/main::libgcc-ng-11.2.0-h1234567_1 --> conda-forge::libgcc-ng-13.2.0-h807b86a_5 
  libgomp              pkgs/main::libgomp-11.2.0-h1234567_1 --> conda-forge::libgomp-13.2.0-h807b86a_5 
  libuuid              pkgs/main::libuuid-1.41.5-h5eee18b_0 --> conda-forge::libuuid-2.38.1-h0b41bf4_0 
  openssl              pkgs/main::openssl-3.0.13-h7f8727e_0 --> conda-forge::openssl-3.2.1-hd590300_0 
  python                pkgs/main::python-3.12.1-h996f2a0_0 --> conda-forge::python-3.12.2-hab00c5b_0_cpython 
  tk                        pkgs/main::tk-8.6.12-h1ccaba5_0 --> conda-forge::tk-8.6.13-noxft_h4845f30_101 
  zlib                    pkgs/main::zlib-1.2.13-h5eee18b_0 --> conda-forge::zlib-1.2.13-hd590300_5 

The following packages will be SUPERSEDED by a higher-priority channel:

  _libgcc_mutex           pkgs/main::_libgcc_mutex-0.1-main --> conda-forge::_libgcc_mutex-0.1-conda_forge 
  _openmp_mutex          pkgs/main::_openmp_mutex-5.1-1_gnu --> conda-forge::_openmp_mutex-4.5-2_gnu 
  certifi            pkgs/main/linux-64::certifi-2024.2.2-~ --> conda-forge/noarch::certifi-2024.2.2-pyhd8ed1ab_0 
  conda              pkgs/main::conda-24.1.2-py312h06a4308~ --> conda-forge::conda-24.1.2-py312h7900ff3_0 


Proceed ([y]/n)? y
Invalid choice: y
Proceed ([y]/n)? y


Downloading and Extracting Packages:
                                                                                                                                                                                              
Preparing transaction: done                                                                                                                                                                   
Verifying transaction: done                                                                                                                                                                   
Executing transaction: done                                                                                                                                                                   
lwk@qwfys:~$

安装完成以后,要确保用户目录配置文件.condarcauto_activate_base: false被注释掉,或者将auto_activate_base: false修改为auto_activate_base: true

参考文献

相关推荐
pursue.dreams36 分钟前
Ubuntu安装Jenkins完整教程
linux·ubuntu·jenkins
人工智能训练4 小时前
在ubuntu系统中如何将docker安装在指定目录
linux·运维·服务器·人工智能·ubuntu·docker·ai编程
qing222222228 小时前
Ubuntu设置程序开机自启动:基于.service文件实现
linux·运维·ubuntu
mpb11 小时前
win11安装tensorrt,并适配conda虚拟环境
conda
lzq60311 小时前
Python虚拟环境全指南:venv与conda对比与实践
开发语言·python·conda
lxmyzzs12 小时前
在使用 `resolvconf` 的 Ubuntu 系统上持久化 DNS 设置
linux·运维·ubuntu
老黄编程1 天前
02-ubuntu24.04证书体系架构及证书有关配置文件、工具详细介绍
ubuntu·数字证书
catoop1 天前
在 Windows 中基于 WSL 子系统 Ubuntu 安装配置 conda 示例
windows·ubuntu·conda
老黄编程1 天前
03-gpg(证书管理 )详细范例
linux·运维·ubuntu·数字证书
莱茶荼菜1 天前
Ubuntu 20.04 系统库管理详细教程
linux·运维·ubuntu