Gab*_*ves 6 python scipy julia anaconda pycall
我目前正在将一堆 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
Run Code Online (Sandbox Code Playgroud)
另外,我尝试过的一切,我都在 Windows 10 和 Linux 上尝试过。我不知道该怎么办了!我非常感谢您的帮助!提前致谢!
安装- Julia 的 Python 包接口scipy。Conda
using Conda
Conda.add("scipy")
Run Code Online (Sandbox Code Playgroud)
现在pyimport("scipy")将像魅力一样发挥作用。
请注意,通过自定义 Python 安装,可能会发生各种情况(并且您需要自行管理),因此我建议您使用 Julia 中内置的 Python。
这是切换回内置 Python 的方法:
using Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")
Run Code Online (Sandbox Code Playgroud)