【问题标题】:PyCall can't find scipy in JuliaPyCall 在 Julia 中找不到 scipy
【发布时间】:2020-07-01 16:26:10
【问题描述】:

我目前正在将一堆 matlab 代码重写为 julia。这些代码涉及大量数学运算,尤其是 3D 网格的插值函数。在 matlab 中很容易处理这个问题:我需要做的就是使用interp3 函数。一旦我在 Julia 中找不到任何简单的方法来做类似的事情,我就会尝试通过 PyCall 使用一些 Scipy 功能。 现在,问题来了:我已经安装了 PyCall,将 ENV[PYTHON] 更改为我自己安装的 anaconda 的路径。无论如何,我广泛寻找解决方案,我仍然收到以下错误消息:

julia> pyimport("scipy")
ERROR: PyError (PyImport_ImportModule

The Python package scipy could not be found by pyimport. Usually this means
that you did not install scipy in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

/usr/bin/python3

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the scipy module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia.  As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the scipy module, you can use `pyimport_conda("scipy", PKG)`,
where PKG is the Anaconda package the contains the module scipy,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ModuleNotFoundError'>
ModuleNotFoundError("No module named 'scipy'",)

Stacktrace:
 [1] pyimport(::String) at /home/gabriel/.julia/packages/PyCall/zqDXB/src/PyCall.jl:536
 [2] top-level scope at none:0

此外,我尝试过的所有内容都在 Windows 10 和 Linux 上进行了尝试。我不知道该怎么办了! 我将非常感谢您的帮助!提前致谢!

【问题讨论】:

  • /usr/bin/python3 是你的 conda python 的路径吗?我怀疑您使用的是系统默认的 python 安装,您应该将 ENV["PYTHON"] 设置为安装 SciPy 的特定 conda env。另一种选择是使用 pip 为您的系统范围的 python 安装 SciPy。

标签: python scipy anaconda julia pycall


【解决方案1】:

安装 scipyConda - Julia 对 Python 包的接口。

using Conda
Conda.add("scipy")

现在pyimport("scipy") 将像魅力一样发挥作用。

请注意,使用自定义 Python 安装可能会发生各种事情(您需要自行管理),因此我建议您使用 Julia 内置的 Python。

这是您切换回内置 Python 的方式:

using Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")

【讨论】:

  • 如此简单!已经尝试过类似的方法,不知道出了什么问题。好吧,重要的是,现在这个程序奏效了!非常感谢!
【解决方案2】:

对于我来说,能够指向自定义 python 位置仍然是更可取的。正如https://github.com/JuliaPy/PyCall.jl/issues/569 所说,pycall 重新构建对我有用。 并且记得重启 Julia。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多