赞
踩
本篇文章给大家谈谈python虚拟环境和主环境,以及conda创建python虚拟环境,希望对各位有所帮助,不要忘了收藏本站喔。
Conda可以用于任何语言的包、依赖和环境管理——Python、 R、 Ruby、 Lua、 Scala、 Java、 JavaScript、 C/C++ 、 FORTRAN
Conda 是一个运行在 Windows、 macOS 和 Linux 上的开源软件包管理系统和环境管理系统。Conda 可以快速安装、运行和更新包及其依赖项用python实现流星雨效果的方法详解。Conda 可以轻松地在本地计算机上的环境之间进行创建、保存、加载和切换。它虽然是为 Python 程序创建的,但是可以为任何语言打包和分发软件。
Conda 作为软件包管理器可以帮助您查找和安装软件包。如果您需要一个需要不同版本 Python 的包,则不需要切换到不同的环境管理器,因为 conda 也是一个环境管理器。只需几个命令,您就可以设置一个完全独立的环境来运行不同版本的 Python,与此同时在正常环境中继续运行常用版本的 Python。
在Conda默认配置中,conda 可以安装和管理超过7,500个在repo.Anaconda.com
上由 Anaconda 构建、评审和维护的包。
Conda
[https://docs.conda.io/projects/conda/en/stable/] 包和环境管理器包含在所有版本的 Anaconda
[https://docs.conda.io/projects/conda/en/stable/glossary.html#anaconda-glossary]、 Miniconda
[https://docs.conda.io/projects/conda/en/stable/glossary.html#miniconda-glossary] 和 Anaconda Repository
[https://docs.continuum.io/anaconda-repository/] 中。Conda 也包含在 Anaconda Enterprise
[https://www.anaconda.com/enterprise/] 中,它为 Python、 R、 Node.js、 Java 和其他应用程序栈提供现场企业包和环境管理。Conda也可以从社区conda-forge
[https://anaconda.org/conda-forge/conda] 获取。您也可以在 PyPI
上获取 conda,但是这种途径获取到的版本可能不是最新的。
世界上最流行的开源 Python 发行平台
特点:
缺点:安装文件大,很多包可能用不到,安装后占用磁盘空间
Miniconda 是一个免费的 Conda 最小安装程序。它是 Anaconda 的一个小型的引导版本,只包含 conda、 Python、它们所依赖的包以及少量其他有用的包,包括 pip、 zlib 和其他一些包。使用 conda install
命令从 Anaconda 存储库安装720多个附加 conda 包。
特点:相比Anaconda安装文件体积小,可以按照实际需求安装相关依赖和包。
在浏览器地址栏中输入 https://docs.conda.io/en/latest/miniconda.html 打开Miniconda官网
根据操作系统选择相应的安装文件,我这里使用的是64位Ubuntu 22.04.1 LTS
(Linux的一个发行版,如下图所示),因而选择上图中的Miniconda3 Linux 64-bit
链接进行下载,下载完成后文件名为Miniconda3-latest-Linux-x86_64.sh
,这里下载的文件可以通过SHA256 hash来校验文件的完整性(具体方法可以自行百度)
为什么要用校验安装文件完整性?简单来说,如果安装文件不完整,可能会导致安装失败。
打开终端,进入安装文件所在目录,输入bash Miniconda3-latest-Linux-x86_64.sh
如上图所示,提示按回车键Enter
键继续
如上图所示,按PageDown
键到底部,会看到提示:
Do you accept the license terms? [yes|no]
输入yes
按回车,会看到提示:
- Miniconda3 will now be installed into this location:
- /home/mjl/miniconda3
-
- - Press ENTER to confirm the location
- - Press CTRL-C to abort the installation
- - Or specify a different location below
-
按回车,会看到提示:
- Do you wish the installer to initialize Miniconda3
- by running conda init? [yes|no]
输入yes
按回车
- no change /home/mjl/miniconda3/condabin/conda
- no change /home/mjl/miniconda3/bin/conda
- no change /home/mjl/miniconda3/bin/conda-env
- no change /home/mjl/miniconda3/bin/activate
- no change /home/mjl/miniconda3/bin/deactivate
- no change /home/mjl/miniconda3/etc/profile.d/conda.sh
- no change /home/mjl/miniconda3/etc/fish/conf.d/conda.fish
- no change /home/mjl/miniconda3/shell/condabin/Conda.psm1
- no change /home/mjl/miniconda3/shell/condabin/conda-hook.ps1
- no change /home/mjl/miniconda3/lib/python3.10/site-packages/xontrib/conda.xsh
- no change /home/mjl/miniconda3/etc/profile.d/conda.csh
- modified /home/mjl/.bashrc
-
- ==> 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 false
-
- Thank you for installing Miniconda3!
至此,安装完成!
安装完成后,第一次使用conda命令可能会无效,只需要关闭终端窗口,重新打开即可在终端窗口中使用conda命令。
在终端窗口中,运行命令conda list
,可以测试测试安装是否成功。
如果已安装软件包已正确安装,则会显示conda内已安装软件包的列表。
关注公众号【十年磨一剑2020】,回复关键字【conda】获取conda各发行版下载链接。
linux下修改 ~/.condarc
文件,添加清华镜像源
- 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
- simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
- channels:
- - defaults
- - conda-forge
附:国内常用镜像源
可以参考以下链接按需进行配置:
清华镜像源:
https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/
中科大镜像源:
https://mirrors.ustc.edu.cn/help/anaconda.html
阿里云镜像源:
https://developer.aliyun.com/mirror/anaconda
命令:
conda env list
操作如下:
- (base) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- base * /home/mjl/miniconda3
- novelai /home/mjl/miniconda3/envs/novelai
从上面的输出可以看到,默认的 base
环境和自己安装的环境名称为 novelai
。
命令:
- (base) mjl@ubuntu:~$ conda activate novelai
- (novelai) mjl@ubuntu:~$
从上面的输出可以看到,第一行为默认的 base
环境,命令行前缀前面有 (base) ,输入 conda activate novelai
第二行已经切换为 novelai
环境,命令行前缀前面变成 (novelai)。
切换到base环境(默认环境为base)
conda activate base
或者
conda activate
创建一个名为 crawl
的环境并指定python版本为3.8
conda create -n crawl python=3.8
操作如下:
- (base) mjl@ubuntu:~$ conda create -n crawl python=3.8
- Retrieving notices: ...working... done
- Collecting package metadata (current_repodata.json): done
- Solving environment: done
-
-
- ==> WARNING: A newer version of conda exists. <==
- current version: 23.7.0
- latest version: 23.7.2
-
- Please update conda by running
-
- $ conda update -n base -c defaults conda
-
- Or to minimize the number of packages updated during conda update use
-
- conda install conda=23.7.2
-
-
-
- ## Package Plan ##
-
- environment location: /home/mjl/miniconda3/envs/crawl
-
- added / updated specs:
- - python=3.8
-
-
- The following packages will be downloaded:
-
- package | build
- ---------------------------|-----------------
- libffi-3.4.4 | h6a678d5_0 142 KB defaults
- openssl-3.0.10 | h7f8727e_0 5.2 MB defaults
- pip-23.2.1 | py38h06a4308_0 2.6 MB defaults
- python-3.8.17 | h955ad1f_0 25.3 MB defaults
- setuptools-68.0.0 | py38h06a4308_0 927 KB defaults
- sqlite-3.41.2 | h5eee18b_0 1.2 MB defaults
- wheel-0.38.4 | py38h06a4308_0 63 KB defaults
- xz-5.4.2 | h5eee18b_0 642 KB defaults
- ------------------------------------------------------------
- Total: 36.0 MB
-
- The following NEW packages will be INSTALLED:
-
- _libgcc_mutex anaconda/pkgs/main/linux-64::_libgcc_mutex-0.1-main
- _openmp_mutex anaconda/pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu
- ca-certificates anaconda/pkgs/main/linux-64::ca-certificates-2023.05.30-h06a4308_0
- ld_impl_linux-64 anaconda/pkgs/main/linux-64::ld_impl_linux-64-2.38-h1181459_1
- libffi anaconda/pkgs/main/linux-64::libffi-3.4.4-h6a678d5_0
- libgcc-ng anaconda/pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1
- libgomp anaconda/pkgs/main/linux-64::libgomp-11.2.0-h1234567_1
- libstdcxx-ng anaconda/pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1
- ncurses anaconda/pkgs/main/linux-64::ncurses-6.4-h6a678d5_0
- openssl anaconda/pkgs/main/linux-64::openssl-3.0.10-h7f8727e_0
- pip anaconda/pkgs/main/linux-64::pip-23.2.1-py38h06a4308_0
- python anaconda/pkgs/main/linux-64::python-3.8.17-h955ad1f_0
- readline anaconda/pkgs/main/linux-64::readline-8.2-h5eee18b_0
- setuptools anaconda/pkgs/main/linux-64::setuptools-68.0.0-py38h06a4308_0
- sqlite anaconda/pkgs/main/linux-64::sqlite-3.41.2-h5eee18b_0
- tk anaconda/pkgs/main/linux-64::tk-8.6.12-h1ccaba5_0
- wheel anaconda/pkgs/main/linux-64::wheel-0.38.4-py38h06a4308_0
- xz anaconda/pkgs/main/linux-64::xz-5.4.2-h5eee18b_0
- zlib anaconda/pkgs/main/linux-64::zlib-1.2.13-h5eee18b_0
-
-
- Proceed ([y]/n)? y
-
-
- Downloading and Extracting Packages
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- #
- # To activate this environment, use
- #
- # $ conda activate crawl
- #
- # To deactivate an active environment, use
- #
- # $ conda deactivate
-
-
- (crawl) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- base /home/mjl/miniconda3
- crawl * /home/mjl/miniconda3/envs/crawl
- novelai /home/mjl/miniconda3/envs/novelai
-
- (base) mjl@ubuntu:~$ conda activate crawl
- (crawl) mjl@ubuntu:~$ python --version
- Python 3.8.17
- (crawl) mjl@ubuntu:~$ conda activate
- (base) mjl@ubuntu:~$ python --version
- Python 3.10.8
从上面输出可以看到,新增的 crawl
环境 Python 版本为 3.8.17,默认的 base
环境 Python 版本为 3.10.8
命令:
conda list
操作如下:
- (crawl) mjl@ubuntu:~$ conda list
- # packages in environment at /home/mjl/miniconda3/envs/crawl:
- #
- # Name Version Build Channel
- _libgcc_mutex 0.1 main defaults
- _openmp_mutex 5.1 1_gnu defaults
- ca-certificates 2023.05.30 h06a4308_0 defaults
- ld_impl_linux-64 2.38 h1181459_1 defaults
- libffi 3.4.4 h6a678d5_0 defaults
- libgcc-ng 11.2.0 h1234567_1 defaults
- libgomp 11.2.0 h1234567_1 defaults
- libstdcxx-ng 11.2.0 h1234567_1 defaults
- ncurses 6.4 h6a678d5_0 defaults
- openssl 3.0.10 h7f8727e_0 defaults
- pip 23.2.1 py38h06a4308_0 defaults
- python 3.8.17 h955ad1f_0 defaults
- readline 8.2 h5eee18b_0 defaults
- setuptools 68.0.0 py38h06a4308_0 defaults
- sqlite 3.41.2 h5eee18b_0 defaults
- tk 8.6.12 h1ccaba5_0 defaults
- wheel 0.38.4 py38h06a4308_0 defaults
- xz 5.4.2 h5eee18b_0 defaults
- zlib 1.2.13 h5eee18b_0 defaults
安装requests包
conda install requests
操作如下:
- (crawl) mjl@ubuntu:~$ conda install requests
- Collecting package metadata (current_repodata.json): done
- Solving environment: done
-
-
- ==> WARNING: A newer version of conda exists. <==
- current version: 23.7.0
- latest version: 23.7.2
-
- Please update conda by running
-
- $ conda update -n base -c defaults conda
-
- Or to minimize the number of packages updated during conda update use
-
- conda install conda=23.7.2
-
-
-
- ## Package Plan ##
-
- environment location: /home/mjl/miniconda3/envs/crawl
-
- added / updated specs:
- - requests
-
-
- The following packages will be downloaded:
-
- package | build
- ---------------------------|-----------------
- brotlipy-0.7.0 |py38h27cfd23_1003 323 KB defaults
- certifi-2023.7.22 | py38h06a4308_0 153 KB defaults
- cffi-1.15.1 | py38h5eee18b_3 241 KB defaults
- cryptography-41.0.2 | py38h22a60cf_0 1.9 MB defaults
- idna-3.4 | py38h06a4308_0 93 KB defaults
- pyopenssl-23.2.0 | py38h06a4308_0 96 KB defaults
- pysocks-1.7.1 | py38h06a4308_0 31 KB defaults
- requests-2.31.0 | py38h06a4308_0 96 KB defaults
- urllib3-1.26.16 | py38h06a4308_0 200 KB defaults
- ------------------------------------------------------------
- Total: 3.1 MB
-
- The following NEW packages will be INSTALLED:
-
- brotlipy anaconda/pkgs/main/linux-64::brotlipy-0.7.0-py38h27cfd23_1003
- certifi anaconda/pkgs/main/linux-64::certifi-2023.7.22-py38h06a4308_0
- cffi anaconda/pkgs/main/linux-64::cffi-1.15.1-py38h5eee18b_3
- charset-normalizer anaconda/pkgs/main/noarch::charset-normalizer-2.0.4-pyhd3eb1b0_0
- cryptography anaconda/pkgs/main/linux-64::cryptography-41.0.2-py38h22a60cf_0
- idna anaconda/pkgs/main/linux-64::idna-3.4-py38h06a4308_0
- pycparser anaconda/pkgs/main/noarch::pycparser-2.21-pyhd3eb1b0_0
- pyopenssl anaconda/pkgs/main/linux-64::pyopenssl-23.2.0-py38h06a4308_0
- pysocks anaconda/pkgs/main/linux-64::pysocks-1.7.1-py38h06a4308_0
- requests anaconda/pkgs/main/linux-64::requests-2.31.0-py38h06a4308_0
- urllib3 anaconda/pkgs/main/linux-64::urllib3-1.26.16-py38h06a4308_0
-
-
- Proceed ([y]/n)? y
-
-
- Downloading and Extracting Packages
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- (crawl) mjl@ubuntu:~$
- (crawl) mjl@ubuntu:~$ conda list
- # packages in environment at /home/mjl/miniconda3/envs/crawl:
- #
- # Name Version Build Channel
- _libgcc_mutex 0.1 main defaults
- _openmp_mutex 5.1 1_gnu defaults
- brotlipy 0.7.0 py38h27cfd23_1003 defaults
- ca-certificates 2023.05.30 h06a4308_0 defaults
- certifi 2023.7.22 py38h06a4308_0 defaults
- cffi 1.15.1 py38h5eee18b_3 defaults
- charset-normalizer 2.0.4 pyhd3eb1b0_0 defaults
- cryptography 41.0.2 py38h22a60cf_0 defaults
- idna 3.4 py38h06a4308_0 defaults
- ld_impl_linux-64 2.38 h1181459_1 defaults
- libffi 3.4.4 h6a678d5_0 defaults
- libgcc-ng 11.2.0 h1234567_1 defaults
- libgomp 11.2.0 h1234567_1 defaults
- libstdcxx-ng 11.2.0 h1234567_1 defaults
- ncurses 6.4 h6a678d5_0 defaults
- openssl 3.0.10 h7f8727e_0 defaults
- pip 23.2.1 py38h06a4308_0 defaults
- pycparser 2.21 pyhd3eb1b0_0 defaults
- pyopenssl 23.2.0 py38h06a4308_0 defaults
- pysocks 1.7.1 py38h06a4308_0 defaults
- python 3.8.17 h955ad1f_0 defaults
- readline 8.2 h5eee18b_0 defaults
- requests 2.31.0 py38h06a4308_0 defaults
- setuptools 68.0.0 py38h06a4308_0 defaults
- sqlite 3.41.2 h5eee18b_0 defaults
- tk 8.6.12 h1ccaba5_0 defaults
- urllib3 1.26.16 py38h06a4308_0 defaults
- wheel 0.38.4 py38h06a4308_0 defaults
- xz 5.4.2 h5eee18b_0 defaults
- zlib 1.2.13 h5eee18b_0 defaults
卸载requets包
conda remove requests
操作如下:
- (crawl) mjl@ubuntu:~$ conda remove requests
- Collecting package metadata (repodata.json): done
- Solving environment: done
-
-
- ==> WARNING: A newer version of conda exists. <==
- current version: 23.7.0
- latest version: 23.7.2
-
- Please update conda by running
-
- $ conda update -n base -c defaults conda
-
- Or to minimize the number of packages updated during conda update use
-
- conda install conda=23.7.2
-
-
-
- ## Package Plan ##
-
- environment location: /home/mjl/miniconda3/envs/crawl
-
- removed specs:
- - requests
-
-
- The following packages will be REMOVED:
-
- brotlipy-0.7.0-py38h27cfd23_1003
- cffi-1.15.1-py38h5eee18b_3
- charset-normalizer-2.0.4-pyhd3eb1b0_0
- cryptography-41.0.2-py38h22a60cf_0
- idna-3.4-py38h06a4308_0
- pycparser-2.21-pyhd3eb1b0_0
- pyopenssl-23.2.0-py38h06a4308_0
- pysocks-1.7.1-py38h06a4308_0
- requests-2.31.0-py38h06a4308_0
- urllib3-1.26.16-py38h06a4308_0
-
-
- Proceed ([y]/n)? y
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- (crawl) mjl@ubuntu:~$ conda list
- # packages in environment at /home/mjl/miniconda3/envs/crawl:
- #
- # Name Version Build Channel
- _libgcc_mutex 0.1 main defaults
- _openmp_mutex 5.1 1_gnu defaults
- ca-certificates 2023.05.30 h06a4308_0 defaults
- certifi 2023.7.22 py38h06a4308_0 defaults
- ld_impl_linux-64 2.38 h1181459_1 defaults
- libffi 3.4.4 h6a678d5_0 defaults
- libgcc-ng 11.2.0 h1234567_1 defaults
- libgomp 11.2.0 h1234567_1 defaults
- libstdcxx-ng 11.2.0 h1234567_1 defaults
- ncurses 6.4 h6a678d5_0 defaults
- openssl 3.0.10 h7f8727e_0 defaults
- pip 23.2.1 py38h06a4308_0 defaults
- python 3.8.17 h955ad1f_0 defaults
- readline 8.2 h5eee18b_0 defaults
- setuptools 68.0.0 py38h06a4308_0 defaults
- sqlite 3.41.2 h5eee18b_0 defaults
- tk 8.6.12 h1ccaba5_0 defaults
- wheel 0.38.4 py38h06a4308_0 defaults
- xz 5.4.2 h5eee18b_0 defaults
- zlib 1.2.13 h5eee18b_0 defaults
导出当前环境的包信息
conda env export > environment.yaml
操作如下:
- (crawl) mjl@ubuntu:~$ conda env export > env_crawl.yaml
- (crawl) mjl@ubuntu:~$ cat env_crawl.yaml
- name: crawl
- channels:
- - defaults
- - conda-forge
- dependencies:
- - _libgcc_mutex=0.1=main
- - _openmp_mutex=5.1=1_gnu
- - ca-certificates=2023.05.30=h06a4308_0
- - certifi=2023.7.22=py38h06a4308_0
- - ld_impl_linux-64=2.38=h1181459_1
- - libffi=3.4.4=h6a678d5_0
- - libgcc-ng=11.2.0=h1234567_1
- - libgomp=11.2.0=h1234567_1
- - libstdcxx-ng=11.2.0=h1234567_1
- - ncurses=6.4=h6a678d5_0
- - openssl=3.0.10=h7f8727e_0
- - pip=23.2.1=py38h06a4308_0
- - python=3.8.17=h955ad1f_0
- - readline=8.2=h5eee18b_0
- - setuptools=68.0.0=py38h06a4308_0
- - sqlite=3.41.2=h5eee18b_0
- - tk=8.6.12=h1ccaba5_0
- - wheel=0.38.4=py38h06a4308_0
- - xz=5.4.2=h5eee18b_0
- - zlib=1.2.13=h5eee18b_0
- prefix: /home/mjl/miniconda3/envs/crawl
删除 crawl
环境及下属所有包
conda remove -n crawl --all
在 crawl
环境中直接执行 conda remove -n crawl --all
会报错,需要先执行conda deactivate
, 然后在 base
环境中执行删除命令,具体操作如下:
- (crawl) mjl@ubuntu:~$ conda remove -n crawl --all
-
- CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again
- (crawl) mjl@ubuntu:~$ conda deactivate
- (base) mjl@ubuntu:~$
- (base) mjl@ubuntu:~$ conda remove -n crawl --all
-
- Remove all packages in environment /home/mjl/miniconda3/envs/crawl:
-
-
- ## Package Plan ##
-
- environment location: /home/mjl/miniconda3/envs/crawl
-
-
- The following packages will be REMOVED:
-
- _libgcc_mutex-0.1-main
- _openmp_mutex-5.1-1_gnu
- ca-certificates-2023.05.30-h06a4308_0
- certifi-2023.7.22-py38h06a4308_0
- ld_impl_linux-64-2.38-h1181459_1
- libffi-3.4.4-h6a678d5_0
- libgcc-ng-11.2.0-h1234567_1
- libgomp-11.2.0-h1234567_1
- libstdcxx-ng-11.2.0-h1234567_1
- ncurses-6.4-h6a678d5_0
- openssl-3.0.10-h7f8727e_0
- pip-23.2.1-py38h06a4308_0
- python-3.8.17-h955ad1f_0
- readline-8.2-h5eee18b_0
- setuptools-68.0.0-py38h06a4308_0
- sqlite-3.41.2-h5eee18b_0
- tk-8.6.12-h1ccaba5_0
- wheel-0.38.4-py38h06a4308_0
- xz-5.4.2-h5eee18b_0
- zlib-1.2.13-h5eee18b_0
-
-
- Proceed ([y]/n)? y
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- (base) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- base * /home/mjl/miniconda3
- novelai /home/mjl/miniconda3/envs/novelai
用配置文件创建新的虚拟环境
conda env create -f environment.yaml
如果没有执行上一步的
conda remove -n crawl --all
删除crawl
环境,直接执行conda env create -f env_crawl.yaml
,则会出现以下错误提示:
- (crawl) mjl@ubuntu:~$ conda env create -f env_crawl.yaml
-
- CondaValueError: prefix already exists: /home/mjl/miniconda3/envs/crawl
在已经删除 crawl
环境的情况下,具体操作如下:
- (base) mjl@ubuntu:~$ conda env create -f env_crawl.yaml
- Collecting package metadata (repodata.json): done
- Solving environment: done
-
-
- ==> WARNING: A newer version of conda exists. <==
- current version: 23.7.0
- latest version: 23.7.2
-
- Please update conda by running
-
- $ conda update -n base -c defaults conda
-
- Or to minimize the number of packages updated during conda update use
-
- conda install conda=23.7.2
-
-
-
- Downloading and Extracting Packages
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- #
- # To activate this environment, use
- #
- # $ conda activate crawl
- #
- # To deactivate an active environment, use
- #
- # $ conda deactivate
-
- (base) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- base * /home/mjl/miniconda3
- crawl /home/mjl/miniconda3/envs/crawl
- novelai /home/mjl/miniconda3/envs/novelai
-
- (base) mjl@ubuntu:~$ conda activate crawl
- (crawl) mjl@ubuntu:~$ conda list
- # packages in environment at /home/mjl/miniconda3/envs/crawl:
- #
- # Name Version Build Channel
- _libgcc_mutex 0.1 main defaults
- _openmp_mutex 5.1 1_gnu defaults
- ca-certificates 2023.05.30 h06a4308_0 defaults
- certifi 2023.7.22 py38h06a4308_0 defaults
- ld_impl_linux-64 2.38 h1181459_1 defaults
- libffi 3.4.4 h6a678d5_0 defaults
- libgcc-ng 11.2.0 h1234567_1 defaults
- libgomp 11.2.0 h1234567_1 defaults
- libstdcxx-ng 11.2.0 h1234567_1 defaults
- ncurses 6.4 h6a678d5_0 defaults
- openssl 3.0.10 h7f8727e_0 defaults
- pip 23.2.1 py38h06a4308_0 defaults
- python 3.8.17 h955ad1f_0 defaults
- readline 8.2 h5eee18b_0 defaults
- setuptools 68.0.0 py38h06a4308_0 defaults
- sqlite 3.41.2 h5eee18b_0 defaults
- tk 8.6.12 h1ccaba5_0 defaults
- wheel 0.38.4 py38h06a4308_0 defaults
- xz 5.4.2 h5eee18b_0 defaults
- zlib 1.2.13 h5eee18b_0 defaults
最终我们可以看到 crawl
环境已经创建成功。
命令:
conda create -n 新环境的名称 --clone 原环境名称
具体操作如下:
- (crawl) mjl@ubuntu:~$ conda create -n crawl-clone --clone crawl
- Source: /home/mjl/miniconda3/envs/crawl
- Destination: /home/mjl/miniconda3/envs/crawl-clone
- Packages: 20
- Files: 0
-
- Downloading and Extracting Packages
-
-
- Downloading and Extracting Packages
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- #
- # To activate this environment, use
- #
- # $ conda activate crawl-clone
- #
- # To deactivate an active environment, use
- #
- # $ conda deactivate
-
- (crawl) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- ba /home/mjl/miniconda3
- crawl * /home/mjl/miniconda3/envs/crawl
- crawl-clone /home/mjl/miniconda3/envs/crawl-clone
- novelai /home/mjl/miniconda3/envs/novelai
在 base
环境下执行 conda install -c conda-forge conda-pack
- (crawl) mjl@ubuntu:~$ conda activate
- (base) mjl@ubuntu:~$ conda install -c conda-forge conda-pack
- Collecting package metadata (current_repodata.json): done
- Solving environment: done
-
-
- ==> WARNING: A newer version of conda exists. <==
- current version: 23.7.0
- latest version: 23.7.2
-
- Please update conda by running
-
- $ conda update -n base -c defaults conda
-
- Or to minimize the number of packages updated during conda update use
-
- conda install conda=23.7.2
-
-
-
- ## Package Plan ##
-
- environment location: /home/mjl/miniconda3
-
- added / updated specs:
- - conda-pack
-
-
- The following packages will be downloaded:
-
- package | build
- ---------------------------|-----------------
- conda-23.7.2 | py310hff52083_0 1006 KB conda-forge
- openssl-1.1.1v | h7f8727e_0 3.7 MB defaults
- python_abi-3.10 | 2_cp310 4 KB conda-forge
- ------------------------------------------------------------
- Total: 4.7 MB
-
- The following NEW packages will be INSTALLED:
-
- conda-pack conda-forge/noarch::conda-pack-0.7.0-pyh6c4a22f_0
- python_abi conda-forge/linux-64::python_abi-3.10-2_cp310
-
- The following packages will be UPDATED:
-
- ca-certificates anaconda/pkgs/main::ca-certificates-2~ --> conda-forge::ca-certificates-2023.7.22-hbcca054_0
- conda anaconda/pkgs/main::conda-23.7.0-py31~ --> conda-forge::conda-23.7.2-py310hff52083_0
- openssl 1.1.1u-h7f8727e_0 --> 1.1.1v-h7f8727e_0
-
- The following packages will be SUPERSEDED by a higher-priority channel:
-
- certifi anaconda/pkgs/main/linux-64::certifi-~ --> conda-forge/noarch::certifi-2023.7.22-pyhd8ed1ab_0
-
-
- Proceed ([y]/n)? y
-
-
- Downloading and Extracting Packages
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
-
命令:
conda pack -n 新环境名称 -o 新环境名称.tar.gz
具体操作如下:
- (base) mjl@ubuntu:~$ conda pack -n crawl-clone -o crawl-clone.tar.gz
- Collecting packages...
- Packing environment at '/home/mjl/miniconda3/envs/crawl-clone' to 'crawl-clone.tar.gz'
- [########################################] | 100% Completed | 6.3s
- (base) mjl@ubuntu:~$ mkdir /home/mjl/miniconda3/envs/crawl-clone2
- (base) mjl@ubuntu:~$ tar -zxvf crawl-clone.tar.gz -C /home/mjl/miniconda3/envs/crawl-clone2
- (base) mjl@ubuntu:~$ conda env list
- # conda environments:
- #
- base * /home/mjl/miniconda3
- crawl /home/mjl/miniconda3/envs/crawl
- crawl-clone /home/mjl/miniconda3/envs/crawl-clone
- crawl-clone2 /home/mjl/miniconda3/envs/crawl-clone2
- novelai /home/mjl/miniconda3/envs/novelai
-
- (base) mjl@ubuntu:~$ conda activate crawl-clone2
- (crawl-clone2) mjl@ubuntu:~$
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。