简体   繁体   English

从源代码构建后无法导入 scipy

[英]Can't import scipy after building from source

I need to use some functionality recently added to Scipy master and not included in 1.5.4.我需要使用一些最近添加到 Scipy master 而未包含在 1.5.4 中的功能。

I've built scipy from source on my home PC (Ubuntu 18) and it runs fine.我已经在我的家用 PC (Ubuntu 18) 上从源代码构建了 scipy,它运行良好。

I now need to deploy my code on my university's HPC cluster (running Redhat Enterprise).我现在需要在我大学的 HPC 集群(运行 Redhat Enterprise)上部署我的代码。

I've executed the following commands to install Scipy from source there:我执行了以下命令从源代码安装 Scipy:

$ mkdir custom_modules
$ cd custom_modules
$ git clone https://github.com/scipy/scipy.git
$ mv scipy scipy_dev
$ pip install --upgrade pip
$ pip install cython
$ pip install pybind11
$ cd scipy_dev
$ python setup.py build --compiler=intelem --fcompiler=intelem
$ python setup.py install --user
$ export PYTHONPATH=$PYTHONPATH:/home/ucfarm0/custom_modules/scipy_dev

This seems to work fine.这似乎工作正常。

I then try to run a test script from my home directory: ($ python3 test.py):然后,我尝试从我的主目录运行一个测试脚本:($ python3 test.py):

import scipy
print(scipy.__version__)

I get the following error message我收到以下错误消息

ImportError: Error importing SciPy: you cannot import SciPy while
        being in scipy source directory; please exit the SciPy source
        tree first and relaunch your Python interpreter.

This is served up to me from the scipy __init__ file.这是由 scipy __init__文件提供给我的。

I don't understand why I'm getting this error because I'm not calling the script from the scipy source directory.我不明白为什么会出现此错误,因为我没有从 scipy 源目录调用脚本。 I imagine it's something to do with my PYTHONPATH pointing there.我想这与我指向那里的 PYTHONPATH 有关。 But if it didn't how would I ever be able to import?但如果没有,我怎么能导入呢? And why isn't this a problem on my home PC?为什么这在我的家用电脑上不是问题?

You should never set the system $PYTHONPATH variable to the SciPy root directory.永远不要将系统 $PYTHONPATH 变量设置为 SciPy 根目录。

This is because when you run setup.py, it is set up in your site-packages directory.这是因为当你运行 setup.py 时,它是在你的 site-packages 目录中设置的。 You can't just run it out of the box (ie from wherever you downloaded it to), because the fortran elements to be installed.您不能开箱即用(即从您下载它的任何地方)运行它,因为要安装 fortran 个元素。

The code was working on my home computer because the install had worked successfully and scipy was in site packages, and I'd luckily set PYTHONPATH wrong so didn't get the error messages.该代码在我的家用计算机上运行,因为安装成功并且 scipy 在站点包中,幸运的是我将 PYTHONPATH 设置错误,所以没有收到错误消息。

I finally managed to Install SciPy from source on the HPC, instructions below:我终于设法在 HPC 上从源代码安装 SciPy,说明如下:

Set up a Virtual Env and Install Modules

#######################
Download and Install SciPy
#######################

$ module unload compilers mpi
$ module load compilers/gnu/4.9.2
$ module load python/3.7.4
$ virtualenv inverse_smrt
$ source inverse_smrt/bin/activate
$ cd inverse_smrt
$ git clone https://github.com/scipy/scipy.git
$ pip install --upgrade pip
$ pip install numpy cython pybind11 xarray six pandas matplotlib xlrd

$ module load lapack openblas
$ echo $OPENBLASROOT
-> /shared/ucl/apps/openblas/0.3.7-serial/gnu-4.9.2

$ mv scipy scipy_dev
$ cd scipy_dev
$ cp site.cfg.example site.cfg
$ nano site.cfg

    Modify the [openblas] section to:

    [openblas]
    libraries = openblas
    library_dirs = /shared/ucl/apps/openblas/0.3.7-serial/gnu-4.9.2/lib
    include_dirs = /shared/ucl/apps/openblas/0.3.7-serial/gnu-4.9.2/include
    runtime_library_dirs = /shared/ucl/apps/openblas/0.3.7-serial/gnu-4.9.2/lib

$ pip install .
$ cd ..
$ nano test.py
    Import scipy
    print(scipy.__version__)
$ which python
$ python test.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM