【发布时间】: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