Conda 骨架 pypi:ModuleNotFoundError:没有名为“numpy”的模块

Ene*_*gya 2 linux numpy python-3.x anaconda conda

我正在尝试按照本教程从我上传到 PyPI 的包创建 conda 包。我已经下载并安装了最新的 Linux Anaconda 环境(Ubuntu 16.04)。

安装后,conda-build我可以conda skeleton pypi click按照示例运行命令,但为我自己的包运行它时mf2,我遇到错误:

ModuleNotFoundError: No module named 'numpy'
Run Code Online (Sandbox Code Playgroud)

导致

Error: command failed: <anaconda_path>/python setup.py install
Run Code Online (Sandbox Code Playgroud)

我已经尝试遵循https://github.com/conda/conda/issues/824的建议,但这对我没有帮助:

$ conda install -n _build numpy

EnvironmentLocationNotFound: Not a conda environment: /scratch/anaconda3/envs/_build

$ conda install -n base numpy
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它发挥作用?问题是 numpy 未安装在它创建的临时环境中吗?如果是这样,我如何确保它有效?

完整输出:

$ conda --version
conda 4.8.1

$ which python
/scratch/anaconda3/bin/python
$ python --version
Python 3.7.4

$ conda skeleton pypi mf2
Warning, the following versions were found for mf2
2019.11.2
2019.11.3
Using 2019.11.3
Use --version to specify a different version.
Using url https://files.pythonhosted.org/packages/cc/15/a2fe948e5fdbf9ca3c5e0c18631a1ec7268ff4dcb62b10e0f0b329cbfdce/mf2-2019.11.3.tar.gz (13 KB) for mf2.
Downloading mf2
PyPI URL:  https://files.pythonhosted.org/packages/cc/15/a2fe948e5fdbf9ca3c5e0c18631a1ec7268ff4dcb62b10e0f0b329cbfdce/mf2-2019.11.3.tar.gz
Unpacking mf2...
done
working in /tmp/tmp9da0e5rkconda_skeleton_mf2-2019.11.3.tar.gz
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: /scratch/anaconda3/conda-bld/skeleton_1578498754522/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place


The following NEW packages will be INSTALLED:

    _libgcc_mutex:    0.1-main               
    ca-certificates:  2019.11.27-0           
    certifi:          2019.11.28-py37_0      
    ld_impl_linux-64: 2.33.1-h53a641e_7      
    libedit:          3.1.20181209-hc058e9b_0
    libffi:           3.2.1-hd88cf55_4       
    libgcc-ng:        9.1.0-hdf63c60_0       
    libstdcxx-ng:     9.1.0-hdf63c60_0       
    ncurses:          6.1-he6710b0_1         
    openssl:          1.1.1d-h7b6447c_3      
    pip:              19.3.1-py37_0          
    python:           3.7.6-h0371630_1       
    pyyaml:           5.2-py37h7b6447c_0     
    readline:         7.0-h7b6447c_5         
    setuptools:       44.0.0-py37_0          
    sqlite:           3.30.1-h7b6447c_0      
    tk:               8.6.8-hbc83047_0       
    wheel:            0.33.6-py37_0          
    xz:               5.2.4-h14c3975_4       
    yaml:             0.1.7-had09818_2       
    zlib:             1.2.11-h7b6447c_3      

Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
Applying patch: '/tmp/tmp9da0e5rkconda_skeleton_mf2-2019.11.3.tar.gz/pypi-distutils.patch'
Trying to apply patch as-is
INFO:conda_build.source:Trying to apply patch as-is
INFO conda_build.source:apply_patch(596): Trying to apply patch as-is
patching file core.py
Hunk #1 succeeded at 167 with fuzz 2 (offset 1 line).
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    import mf2
  File "/tmp/tmp9da0e5rkconda_skeleton_mf2-2019.11.3.tar.gz/mf2-2019.11.3/mf2/__init__.py", line 9, in <module>
    from .multiFidelityFunction import MultiFidelityFunction
  File "/tmp/tmp9da0e5rkconda_skeleton_mf2-2019.11.3.tar.gz/mf2-2019.11.3/mf2/multiFidelityFunction.py", line 12, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'
$PYTHONPATH = /tmp/tmp9da0e5rkconda_skeleton_mf2-2019.11.3.tar.gz/mf2-2019.11.3

Leaving build/test directories:
  Work:
 /scratch/anaconda3/conda-bld/skeleton_1578498754522/work 
  Test:
 /scratch/anaconda3/conda-bld/skeleton_1578498754522/test_tmp 
Leaving build/test environments:
  Test:
source activate  /scratch/anaconda3/conda-bld/skeleton_1578498754522/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_ 
  Build:
source activate  /scratch/anaconda3/conda-bld/skeleton_1578498754522/_build_env 


Error: command failed: /scratch/anaconda3/conda-bld/skeleton_1578498754522/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_place/bin/python setup.py install
Run Code Online (Sandbox Code Playgroud)

mer*_*erv 6

我怀疑 GitHub 问题中的建议已经过时了。当前版本conda skeleton pypi并不真正关心活动环境,也不使用_build,而是创建一个临时环境,在其中尝试安装包并最终输出配方。人们可以使用该标志向临时环境添加额外的要求--extra-specs。在你的情况下,这应该是这样的

conda skeleton pypi --extra-specs numpy mf2
Run Code Online (Sandbox Code Playgroud)

由于--extra-specs参数使用action='append'from的设置argparse,这意味着应该添加多个额外的规范和附加标志。例如,

conda skeleton pypi --extra-specs numpy --extra-specs scipy mf2
Run Code Online (Sandbox Code Playgroud)