IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> macOS下anaconda 虚拟环境及依赖包管理 -> 正文阅读

[Python知识库]macOS下anaconda 虚拟环境及依赖包管理

环境管理(适用mac)

//检查conda版本或是否已经安装
(base) lzh:~ mac$ conda --version
conda 4.10.1

// 检查依赖包
(base) lzh:~ mac$ conda list
# packages in environment at /Users/mac/opt/anaconda3:
...

// 更新anaconda(一般情况下不用)
(base) lzh:~ mac$ conda update conda
Collecting package metadata (current_repodata.json): done
Solving environment: done
...

//创建一个名称为"validator_sd"的python版本为3.8的虚拟环境
(base) lzh:envs mac$ conda create --name validator_sd python=3.8
Collecting package metadata (current_repodata.json): done
Solving environment: done
...

// 若创建不成功, 先清除缓存的pkg
(base) lzh:envs mac$ conda clean --all
...
可以进入相应的目录下,删除相应文件
再删除anaconda3/envs/目录下你刚刚新建的虚拟环境的目录,再conda create

// macOS和linux下, 切换虚拟环境
(base) lzh:envs mac$ source activate validator_sd
(validator_sd) lzh:envs mac$

// macOS和linux下, 切换虚拟环境方式2
(base) lzh:envs mac$ conda activate validator_sd
(validator_sd) lzh:envs mac$

// macOS和linux下, 退出当前虚拟环境
(validator_sd) lzh:envs mac$ conda deactivate
(base) lzh:envs mac$

// 列出已经创建的虚拟环境
(validator_sd) lzh:envs mac$ conda env list
# conda environments:
#
base                     /Users/mac/opt/anaconda3


// 复制一个虚拟环境, 从validator_sd复制出一个虚拟环境,名称为validator
(validator_sd) lzh:conda-meta mac$ conda create --name validator --clone validator_sd
Source:      /Users/mac/opt/anaconda3/envs/validator_sd
Destination: /Users/mac/opt/anaconda3/envs/validator
Packages: 0
Files: 0
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate validator
#
# To deactivate an active environment, use
#
#     $ conda deactivate


// 删除一个名 validator的虚拟环境
(validator_sd) lzh:conda-meta mac$ conda remove --name validator --all

Remove all packages in environment /Users/mac/opt/anaconda3/envs/validator:

No packages found in /Users/mac/opt/anaconda3/envs/validator. Continuing environment removal

1.2 创建虚拟环境失败后,排查问题,并再次成功创建虚拟环境的过程

## 创建虚拟环境报错了
(base) lzh:envs mac$ conda create --name valicator_sd python=3.8
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/mac/opt/anaconda3/envs/valicator_sd

  added / updated specs:
    - python=3.8


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2022.3.29  |       hecd8cb5_1         122 KB
    openssl-1.1.1n             |       hca72f7f_0         2.2 MB
    python-3.8.13              |       hdfd78df_0        10.8 MB
    setuptools-61.2.0          |   py38hecd8cb5_0        1012 KB
    sqlite-3.38.2              |       h707629a_0         1.2 MB
    zlib-1.2.12                |       h4dc903c_1          97 KB
    ------------------------------------------------------------
                                           Total:        15.4 MB

The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/osx-64::ca-certificates-2022.3.29-hecd8cb5_1
  certifi            pkgs/main/osx-64::certifi-2021.10.8-py38hecd8cb5_2
  libcxx             pkgs/main/osx-64::libcxx-12.0.0-h2f01273_0
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  ncurses            pkgs/main/osx-64::ncurses-6.3-hca72f7f_2
  openssl            pkgs/main/osx-64::openssl-1.1.1n-hca72f7f_0
  pip                pkgs/main/osx-64::pip-21.2.4-py38hecd8cb5_0
  python             pkgs/main/osx-64::python-3.8.13-hdfd78df_0
  readline           pkgs/main/osx-64::readline-8.1.2-hca72f7f_1
  setuptools         pkgs/main/osx-64::setuptools-61.2.0-py38hecd8cb5_0
  sqlite             pkgs/main/osx-64::sqlite-3.38.2-h707629a_0
  tk                 pkgs/main/osx-64::tk-8.6.11-h7bc2e8c_0
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  xz                 pkgs/main/osx-64::xz-5.2.5-h1de35cc_0
  zlib               pkgs/main/osx-64::zlib-1.2.12-h4dc903c_1


Proceed ([y]/n)? y


Downloading and Extracting Packages
sqlite-3.38.2        | 1.2 MB    | ################################################################################################################################################################# | 100%
ca-certificates-2022 | 122 KB    | ################################################################################################################################################################# | 100%
openssl-1.1.1n       | 2.2 MB    | ################################################################################################################################################################# | 100%
zlib-1.2.12          | 97 KB     | ################################################################################################################################################################# | 100%
setuptools-61.2.0    | 1012 KB   | ################################################################################################################################################################# | 100%
python-3.8.13        | 10.8 MB   | ################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: failed

CondaVerificationError: The package for ncurses located at /Users/mac/opt/anaconda3/pkgs/ncurses-6.3-hca72f7f_2  **//错误点**
appears to be corrupted. The path 'share/terminfo/69/iterm2'
specified in the package manifest cannot be found.

# 下面排查及解决过程
(base) lzh:envs mac$ pwd
/Users/mac/opt/anaconda3/envs
(base) lzh:envs mac$ cd ..
(base) lzh:anaconda3 mac$ cd pkgs/
(base) lzh:pkgs mac$ rm -rf ncurses-6.3-hca72f7f_2/
(base) lzh:pkgs mac$ pwd
/Users/mac/opt/anaconda3/pkgs
(base) lzh:pkgs mac$ cd ..
(base) lzh:anaconda3 mac$ cd envs/
(base) lzh:envs mac$ ll
total 0
drwxr-xr-x   24 mac  staff    768 Apr 21 13:49 apidev38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 etl38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 nlp38
drwxr-xr-x   49 mac  staff   1568 Mar 15 11:49 sse38
drwxr-xr-x    3 mac  staff     96 Apr 21 15:24 valicator_sd
(base) lzh:envs mac$ conda remove --name validator_sd --all
(base) lzh:envs mac$ ll
total 0
drwxr-xr-x   24 mac  staff    768 Apr 21 13:49 apidev38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 etl38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 nlp38
drwxr-xr-x   49 mac  staff   1568 Mar 15 11:49 sse38
drwxr-xr-x    3 mac  staff     96 Apr 21 15:24 valicator_sd
(base) lzh:envs mac$ rm -rf valicator_sd/
(base) lzh:envs mac$ ll
total 0
drwxr-xr-x   24 mac  staff    768 Apr 21 13:49 apidev38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 etl38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 nlp38
drwxr-xr-x   49 mac  staff   1568 Mar 15 11:49 sse38
(base) lzh:envs mac$ conda clean --all
Cache location: /Users/mac/opt/anaconda3/pkgs
Will remove the following tarballs:

/Users/mac/opt/anaconda3/pkgs
-----------------------------
openssl-1.1.1n-hca72f7f_0.conda              2.2 MB
ca-certificates-2022.3.29-hecd8cb5_1.conda     122 KB
zlib-1.2.12-h4dc903c_1.conda                  97 KB
setuptools-61.2.0-py38hecd8cb5_0.conda      1012 KB
sqlite-3.38.2-h707629a_0.conda               1.2 MB
python-3.8.13-hdfd78df_0.conda              10.8 MB

---------------------------------------------------
Total:                                      15.4 MB

Proceed ([y]/n)? y

Removed openssl-1.1.1n-hca72f7f_0.conda
Removed ca-certificates-2022.3.29-hecd8cb5_1.conda
Removed zlib-1.2.12-h4dc903c_1.conda
Removed setuptools-61.2.0-py38hecd8cb5_0.conda
Removed sqlite-3.38.2-h707629a_0.conda
Removed python-3.8.13-hdfd78df_0.conda
WARNING: /Users/mac/.conda/pkgs does not exist
Cache location: /Users/mac/opt/anaconda3/pkgs
Will remove the following packages:
/Users/mac/opt/anaconda3/pkgs
-----------------------------

zlib-1.2.12-h4dc903c_1                       468 KB
sqlite-3.38.2-h707629a_0                     4.2 MB
python-3.8.13-hdfd78df_0                    40.4 MB
setuptools-61.2.0-py38hecd8cb5_0             5.8 MB
openssl-1.1.1n-hca72f7f_0                    9.9 MB
ca-certificates-2022.3.29-hecd8cb5_1         232 KB

---------------------------------------------------
Total:                                      61.0 MB

Proceed ([y]/n)? y

removing zlib-1.2.12-h4dc903c_1
removing sqlite-3.38.2-h707629a_0
removing python-3.8.13-hdfd78df_0
removing setuptools-61.2.0-py38hecd8cb5_0
removing openssl-1.1.1n-hca72f7f_0
removing ca-certificates-2022.3.29-hecd8cb5_1
(base) lzh:envs mac$ ll
total 0
drwxr-xr-x   24 mac  staff    768 Apr 21 13:49 apidev38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 etl38
drwxr-xr-x    9 mac  staff    288 Jun 21  2021 nlp38
drwxr-xr-x   49 mac  staff   1568 Mar 15 11:49 sse38

# 再次创建虚拟环境
(base) lzh:envs mac$ conda create --name validator_sd python=3.8
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/mac/opt/anaconda3/envs/validator_sd

  added / updated specs:
    - python=3.8


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    ca-certificates-2022.3.29  |       hecd8cb5_1         122 KB
    ncurses-6.3                |       hca72f7f_2         856 KB
    openssl-1.1.1n             |       hca72f7f_0         2.2 MB
    python-3.8.13              |       hdfd78df_0        10.8 MB
    setuptools-61.2.0          |   py38hecd8cb5_0        1012 KB
    sqlite-3.38.2              |       h707629a_0         1.2 MB
    zlib-1.2.12                |       h4dc903c_1          97 KB
    ------------------------------------------------------------
                                           Total:        16.2 MB

The following NEW packages will be INSTALLED:

  ca-certificates    pkgs/main/osx-64::ca-certificates-2022.3.29-hecd8cb5_1
  certifi            pkgs/main/osx-64::certifi-2021.10.8-py38hecd8cb5_2
  libcxx             pkgs/main/osx-64::libcxx-12.0.0-h2f01273_0
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  ncurses            pkgs/main/osx-64::ncurses-6.3-hca72f7f_2
  openssl            pkgs/main/osx-64::openssl-1.1.1n-hca72f7f_0
  pip                pkgs/main/osx-64::pip-21.2.4-py38hecd8cb5_0
  python             pkgs/main/osx-64::python-3.8.13-hdfd78df_0
  readline           pkgs/main/osx-64::readline-8.1.2-hca72f7f_1
  setuptools         pkgs/main/osx-64::setuptools-61.2.0-py38hecd8cb5_0
  sqlite             pkgs/main/osx-64::sqlite-3.38.2-h707629a_0
  tk                 pkgs/main/osx-64::tk-8.6.11-h7bc2e8c_0
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  xz                 pkgs/main/osx-64::xz-5.2.5-h1de35cc_0
  zlib               pkgs/main/osx-64::zlib-1.2.12-h4dc903c_1


Proceed ([y]/n)? y


Downloading and Extracting Packages
openssl-1.1.1n       | 2.2 MB    | ################################################################################################################################################################# | 100%
ca-certificates-2022 | 122 KB    | ################################################################################################################################################################# | 100%
python-3.8.13        | 10.8 MB   | ################################################################################################################################################################# | 100%
setuptools-61.2.0    | 1012 KB   | ################################################################################################################################################################# | 100%
ncurses-6.3          | 856 KB    | ################################################################################################################################################################# | 100%
sqlite-3.38.2        | 1.2 MB    | ################################################################################################################################################################# | 100%
zlib-1.2.12          | 97 KB     | ################################################################################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate validator_sd
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) lzh:envs mac$

依赖包管理

# 方法1: 为validator_sd环境安装pandas
(base) lzh:envs mac$ conda install --name validator_sd pandas
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/mac/opt/anaconda3/envs/validator_sd

  added / updated specs:
    - pandas


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    blas-1.0                   |              mkl           6 KB
    bottleneck-1.3.4           |   py38h67323c0_0         115 KB
    intel-openmp-2021.4.0      |    hecd8cb5_3538         961 KB
    mkl-2021.4.0               |     hecd8cb5_637       101.0 MB
    mkl-service-2.4.0          |   py38h9ed2024_0          45 KB
    mkl_fft-1.3.1              |   py38h4ab4a9b_0         165 KB
    mkl_random-1.2.2           |   py38hb2f4e1b_0         273 KB
    numexpr-2.8.1              |   py38h2e5f0a9_0         122 KB
    numpy-1.21.5               |   py38h2e5f0a9_1          24 KB
    numpy-base-1.21.5          |   py38h3b1a694_1         4.7 MB
    packaging-21.3             |     pyhd3eb1b0_0          36 KB
    pandas-1.4.1               |   py38he9d5cce_1         9.3 MB
    pyparsing-3.0.4            |     pyhd3eb1b0_0          81 KB
    python-dateutil-2.8.2      |     pyhd3eb1b0_0         233 KB
    pytz-2021.3                |     pyhd3eb1b0_0         171 KB
    six-1.16.0                 |     pyhd3eb1b0_1          18 KB
    ------------------------------------------------------------
                                           Total:       117.2 MB

The following NEW packages will be INSTALLED:

  blas               pkgs/main/osx-64::blas-1.0-mkl
  bottleneck         pkgs/main/osx-64::bottleneck-1.3.4-py38h67323c0_0
  intel-openmp       pkgs/main/osx-64::intel-openmp-2021.4.0-hecd8cb5_3538
  mkl                pkgs/main/osx-64::mkl-2021.4.0-hecd8cb5_637
  mkl-service        pkgs/main/osx-64::mkl-service-2.4.0-py38h9ed2024_0
  mkl_fft            pkgs/main/osx-64::mkl_fft-1.3.1-py38h4ab4a9b_0
  mkl_random         pkgs/main/osx-64::mkl_random-1.2.2-py38hb2f4e1b_0
  numexpr            pkgs/main/osx-64::numexpr-2.8.1-py38h2e5f0a9_0
  numpy              pkgs/main/osx-64::numpy-1.21.5-py38h2e5f0a9_1
  numpy-base         pkgs/main/osx-64::numpy-base-1.21.5-py38h3b1a694_1
  packaging          pkgs/main/noarch::packaging-21.3-pyhd3eb1b0_0
  pandas             pkgs/main/osx-64::pandas-1.4.1-py38he9d5cce_1
  pyparsing          pkgs/main/noarch::pyparsing-3.0.4-pyhd3eb1b0_0
  python-dateutil    pkgs/main/noarch::python-dateutil-2.8.2-pyhd3eb1b0_0
  pytz               pkgs/main/noarch::pytz-2021.3-pyhd3eb1b0_0
  six                pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1


Proceed ([y]/n)? y
....
# 方法2: 先切换虚拟环境,再使用condate install 或pip install 安装
(base) lzh:envs mac$ conda activate validator_sd
(validator_sd) lzh:envs mac$ conda install pandas
(validator_sd) lzh:envs mac$ pip install pandas




# 方法1: 卸载指定环境的包
(base) lzh:envs mac$ conda remove --name validator_sd pandas

# 方法2:当前环境下卸载包,两个命令都可以
(base) lzh:envs mac$ conda activate validator_sd
(validator_sd) lzh:envs mac$ pip uninstall pandas
(validator_sd) lzh:envs mac$ conda remove pandas

# 更新包:
(base) lzh:envs mac$ conda upgrade --all  // 更新所有包
(base) lzh:envs mac$ conda upgrade pandas  // 更新指定包
  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2022-04-23 10:49:32  更:2022-04-23 10:50:14 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年12日历 -2024/12/28 11:11:13-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码
数据统计