如何从两个版本调用特定的numpy

时间:2019-03-13 12:12:54

标签: python numpy path

运行脚本时,出现以下错误。

/usr/lib64/python2.7/site-packages/scipy/__init__.py:110: UserWarning: Numpy 1.8.2 or above is recommended for this version of scipy (detected version 1.7.1)
  UserWarning)
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
  File "/usr/bin/hicCorrectMatrix", line 4, in <module>
    from hicexplorer.hicCorrectMatrix import main
  File "/usr/lib/python2.7/site-packages/hicexplorer/hicCorrectMatrix.py", line 3, in <module>
    from scipy.sparse import lil_matrix
  File "/usr/lib64/python2.7/site-packages/scipy/sparse/__init__.py", line 229, in <module>
    from .csr import *
  File "/usr/lib64/python2.7/site-packages/scipy/sparse/csr.py", line 15, in <module>
    from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: numpy.core.multiarray failed to import

我正在从hicexplorer运行hicCorrectMatrix。

程序的安装方式为:

/opt/miniconda2/bin/conda install hicexplorer -c bioconda -c conda-forge

看来,这是与路径有关的问题。

I have two versions of numpy.
python2 -c 'import numpy; print (numpy.version.version)'
1.7.1
python3 -c 'import numpy; print (numpy.version.version)'
1.16.2

以某种方式程序正在寻找numpy版本1.7.1而不是1.16.2。

whereis numpy
numpy: /usr/include/numpy

但是,如果我希望升级numpy,我最终会得到。

    pip install numpy --upgrade
    Requirement already up-to-date: numpy in /usr/local/lib/python3.7/site-packages (1.16.2)
    pip3 install numpy --upgrade
    Requirement already up-to-date: numpy in /usr/local/lib/python3.7/site-packages (1.16.2)

/opt/miniconda2/bin/conda install -c conda-forge numpy
Collecting package metadata: done
Solving environment: done

# All requested packages already installed.

请让我知道如何解决此问题。 谢谢。

1 个答案:

答案 0 :(得分:0)

解决了该问题。我必须设置PYTHONPATH变量。

export PYTHONPATH="/opt/miniconda2/lib/python2.7/site-packages/"