python - Anaconda:通过 conda pip 安装的软件包的行为无法解释

标签 python pip anaconda conda

我正在尝试导出使用 conda + pip 构建的 conda env(通过 conda 安装),但我缺少一些通过 pip 安装的软件包。下面是我所遵循的过程的详细信息。

我运行的操作系统是:

bdauser@testsuselinux:~> cat /etc/os-release
NAME="SLES"
VERSION="12-SP3"
VERSION_ID="12.3"
PRETTY_NAME="SUSE Linux Enterprise Server 12 SP3"
ID="sles"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sles:12:sp3"

这是我的 anaconda 版本:

bdauser@testsuselinux:~> conda list anaconda
# packages in environment at /home/bdauser/anaconda3:
#
anaconda                  5.0.1            py36hd30a520_1
anaconda-client           1.6.5            py36h19c0dcd_0
anaconda-navigator        1.6.9            py36h11ddaaa_0
anaconda-project          0.8.0            py36h29abdf5_0

我已经通过以下方式创建并激活了 anaconda env:

bdauser@testsuselinux:~> conda create --name libmad python=3.5
bdauser@testsuselinux:~> source activate libmad

然后我通过以下方式安装了 conda 的 pip:

(libmad) bdauser@testsuselinux:~> conda install pip

然后我使用 pip for conda 成功安装了一个软件包:

(libmad) bdauser@testsuselinux:~> /home/bdauser/anaconda3/envs/libmad/bin/pip install nltk==3.4

我已经检查了该软件包是否确实通过以下方式安装:

(libmad) bdauser@testsuselinux:~/anaconda3/envs/libmad/bin> /home/bdauser/anaconda3/envs/libmad/bin/pip install nltk==3.4
Requirement already satisfied: nltk==3.4 in /home/bdauser/anaconda3/envs/libmad/lib/python3.5/site-packages (3.4)
Requirement already satisfied: six in /home/bdauser/anaconda3/envs/libmad/lib/python3.5/site-packages (from nltk==3.4) (1.12.0)
Requirement already satisfied: singledispatch in /home/bdauser/anaconda3/envs/libmad/lib/python3.5/site-packages (from nltk==3.4) (3.4.0.3)

此时我已尝试导出 conda env:

(libmad) bdauser@testsuselinux:~/anaconda3/envs/libmad/bin> conda env export
name: libmad
channels:
- defaults
dependencies:
- ca-certificates=2019.1.23=0
- certifi=2018.8.24=py35_1
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=8.2.0=hdf63c60_1
- libstdcxx-ng=8.2.0=hdf63c60_1
- ncurses=6.1=he6710b0_1
- openssl=1.0.2r=h7b6447c_0
- pip=10.0.1=py35_0
- python=3.5.6=hc3d631a_0
- readline=7.0=h7b6447c_5
- setuptools=40.2.0=py35_0
- sqlite=3.28.0=h7b6447c_0
- tk=8.6.8=hbc83047_0
- wheel=0.31.1=py35_0
- xz=5.2.4=h14c3975_4
- zlib=1.2.11=h7b6447c_3
prefix: /home/bdauser/anaconda3/envs/libmad

但是如您所见,nltk 并未显示。

我尝试运行一个简单的conda list,我可以看到nltk包:

(libmad) bdauser@testsuselinux:~/anaconda3/envs/libmad/bin> conda list
# packages in environment at /home/bdauser/anaconda3/envs/libmad:
#
ca-certificates           2019.1.23                     0
certifi                   2018.8.24                py35_1
libedit                   3.1.20181209         hc058e9b_0
libffi                    3.2.1                hd88cf55_4
libgcc-ng                 8.2.0                hdf63c60_1
libstdcxx-ng              8.2.0                hdf63c60_1
ncurses                   6.1                  he6710b0_1
nltk                      3.4                       <pip>
openssl                   1.0.2r               h7b6447c_0
pip                       10.0.1                   py35_0
pip                       19.1.1                    <pip>
python                    3.5.6                hc3d631a_0
readline                  7.0                  h7b6447c_5
setuptools                41.0.1                    <pip>
setuptools                40.2.0                   py35_0
singledispatch            3.4.0.3                   <pip>
six                       1.12.0                    <pip>
sqlite                    3.28.0               h7b6447c_0
tk                        8.6.8                hbc83047_0
wheel                     0.31.1                   py35_0
xz                        5.2.4                h14c3975_4
zlib                      1.2.11               h7b6447c_3

如果我使用导出标志运行相同的命令,我不会再次看到 nltk:

(libmad) bdauser@testsuselinux:~/anaconda3/envs/libmad/bin> conda list --export
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
ca-certificates=2019.1.23=0
certifi=2018.8.24=py35_1
libedit=3.1.20181209=hc058e9b_0
libffi=3.2.1=hd88cf55_4
libgcc-ng=8.2.0=hdf63c60_1
libstdcxx-ng=8.2.0=hdf63c60_1
ncurses=6.1=he6710b0_1
openssl=1.0.2r=h7b6447c_0
pip=10.0.1=py35_0
python=3.5.6=hc3d631a_0
readline=7.0=h7b6447c_5
setuptools=40.2.0=py35_0
sqlite=3.28.0=h7b6447c_0
tk=8.6.8=hbc83047_0
wheel=0.31.1=py35_0
xz=5.2.4=h14c3975_4
zlib=1.2.11=h7b6447c_3

谁能解释一下这种行为?我在这里做错了什么?目标是将 conda env 导出到另一台机器,并通过 pip 安装所有软件包。

提前致谢, 阿莱西奥

最佳答案

我怀疑问题是您通过 PyPI 更新了 pip,然后使用它来安装您的软件包。我认为 Conda 在识别不是通过 Conda 安装的 pip 安装的软件包时存在问题。相反,请尝试仅使用通过 Conda 安装的 pip:

conda create -n libmad python=3.5 pip
conda activate libmad
pip install nltk==3.4

提示:如果您处于激活的环境中,则无需提供 pip 的完整路径。

从技术上讲,我们不必在创建步骤中包含 pip,因为只要安装 python,Conda 总是会安装 pip;我们将把它留在这里以备不时之需。另请注意,您可以通过 Conda Forge channel 获取更新版本的 pip(Python 3.5 最高可达 18.0)。

然后,conda env export 给出:

name: libmad
channels:
  - defaults
dependencies:
  - ca-certificates=2019.1.23=0
  - certifi=2018.8.24=py35_1
  - libcxx=4.0.1=hcfea43d_1
  - libcxxabi=4.0.1=hcfea43d_1
  - libedit=3.1.20181209=hb402a30_0
  - libffi=3.2.1=1
  - ncurses=6.1=h0a44026_1
  - openssl=1.0.2r=h1de35cc_0
  - pip=10.0.1=py35_0
  - python=3.5.6=hc167b69_0
  - readline=7.0=h1de35cc_5
  - setuptools=40.2.0=py35_0
  - sqlite=3.28.0=ha441bb4_0
  - tk=8.6.8=ha441bb4_0
  - wheel=0.31.1=py35_0
  - xz=5.2.4=h1de35cc_4
  - zlib=1.2.11=h1de35cc_3
  - pip:
    - nltk==3.4
    - singledispatch==3.4.0.3
    - six==1.12.0

关于python - Anaconda:通过 conda pip 安装的软件包的行为无法解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56152547/

相关文章:

python - 如何在 anaconda 中升级 scikit-learn 包

python - WSGI无法导入本地安装的包

python - 如何从 Dockerfile 安装 Python 3.7 和 Pip

python - 使用 python ctypes 引用不透明类型

python - 如何使 pip 可用于 Windows 上的 git bash 命令行?

python - 为什么 Cython 的 pip 安装需要这么长时间?

python - Anaconda 是否在全局站点包文件夹中搜索包?

python - Spyder IPython 和 "normal"IPython sys.path 之间的区别

python - 导入 matplotlib 时出现 importError tkinter

python - Tensorflow:您必须使用 dtype float 为占位符张量 'Placeholder' 提供一个值 [但该值是一个 float ]