python - PyCall 在 Julia 中找不到 scipy

标签 python scipy anaconda julia pycall

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

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

最佳答案

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

using Conda
Conda.add("scipy")
现在pyimport("scipy")会像魅力一样工作。
请注意,使用自定义 Python 安装可能会发生各种事情(您需要自己管理),因此我建议您使用 Julia 内置的 Python。
这是您切换回内置 Python 的方式:
using Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")

关于python - PyCall 在 Julia 中找不到 scipy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62681223/

相关文章:

python - 稀疏矩阵Python的秩

mingw - Windows 上的 Nuitka

python - [Py安装程序] : Working code produces ModuleNotFoundError when turned to exe

Python 将数组转换为 Wav

Python 正则表达式 - 提取每个表格单元格内容

python - scipy.optimize.linprog - 难以理解参数

python - 从pdf生成概率?

python - Boost.Python TypeError : __init__() should return None not 'NoneType' - but no obvious linker or version problem

python - 'QThread : Destroyed while thread is still running' on quit

python - 在迭代 pandas 数据框时更新它的更好方法