PyCall 在 Julia 中找不到 scipy

PyCall can't find scipy in Julia

我目前正在将一堆 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 上都试过了。我不知道该怎么办了! 非常感谢您的帮助!提前致谢!

使用 Conda 安装 scipy - Julia 与 Python 的包的接口。

using Conda
Conda.add("scipy")

现在 pyimport("scipy") 会很有魅力。

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

这就是您切换回内置 Python:

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

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