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

时间:2019-05-15 15:09:13

标签: 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

如果我对带有export标志的命令运行相同的命令,则不会再看到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安装。

预先感谢, 阿莱西奥

1 个答案:

答案 0 :(得分:2)

我怀疑问题是您通过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,因为只要安装了pip,Conda就会始终安装python。我们会把它留在这里以备不时之需。另请注意,您可以通过Conda Forge渠道获得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