我找到了一个 Julia 函数,可以很好地完成我需要的工作。如何快速集成它以便能够从 Python 调用它?
假设函数是
f(x,y) = 2x.+y
Run Code Online (Sandbox Code Playgroud)
从 Python 中使用它的最佳和最优雅的方法是什么?
我目前正在将一堆 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 …Run Code Online (Sandbox Code Playgroud) 我无法找到将 30,000 x 1,000 Pandas.jl String DataFrame 转换为 DataFrames.jl DataFrame 的方法。我尝试过以前的 stackoverflow 解决方案,但没有成功。我想知道转换数据框的最佳方法是什么。感谢您的帮助。
按照 PyCall.jl readme 上的说明,在我的 julia 项目(在它自己的环境中)使用 PyCall 时,我打算使用 pipenv python。
在终端中,我使用 激活了python环境pipenv shell,然后找到了pipenv版本的python的路径文件。PyCall 已添加到我的 julia 环境中的清单中。在源代码激活的终端中,我启动 Julia 并输入:ENV["PYCALL_JL_RUNTIME_PYTHON"] = pipenv python environment然后继续运行Pkg.build("PyCall"),安装 conda。导入 PyCall 时 - using PyCall- 我收到以下错误。
ERROR: InitError: Incompatible `libpython` detected.
`libpython` for C:\Users\me\.virtualenvs\iap\Scripts\python.exe is:
C:\Users\me\.virtualenvs\iap\Scripts\python37.dll
`libpython` for C:\Users\me\.julia\conda\3\python.exe is:
C:\Users\me\.julia\conda\3\python36.dll
PyCall.jl only supports loading Python environment using the same `libpython`
Run Code Online (Sandbox Code Playgroud)
我试过重新安装 PyCall,但是 python 环境 libpython 总是抛出这个错误。我如何覆盖或以其他方式解决 base julia 的 conda 要求?
我有一种感觉,PyCall 的 Conda 依赖项导致了一些libpython …
我正在尝试使用针对 Julia 函数的 multiprocessing.Process 来并行化 python 中的代码。
当我直接调用它时,即当我执行时,该函数工作正常:
if __name__ == "__main__":
import julia
julia.Julia(compiled_modules=False)
julia.Pkg_jl.func_jl(*args)
Run Code Online (Sandbox Code Playgroud)
但是,当我在Process函数中定义相同的函数作为目标时,出现错误。
这是代码:
from multiprocessing import Process
import julia
julia.Julia(compiled_modules=False)
class JuliaProcess(object):
...
def _wrapper(self, *args):
ret = julia.Pkg_jl.func_jl(args)
self.queue.put(ret) # this is for save the result of the function
def run(self, *args):
p = Process(target=self._wrapper, args=args)
self.processes.append(p) # this is for save the process job
p.start()
...
if __name__ == "__main__":
...
Jlproc = JuliaProcess()
Jlproc.run(some_args)
Run Code Online (Sandbox Code Playgroud)
错误发生在进程启动时,并显示以下输出:
fatal: error thrown and no exception …Run Code Online (Sandbox Code Playgroud) 我使用 Julia 1.6.0(截至今天的测试版)并希望plfit通过PyCall.
不幸的是,plfit在 Anaconda 中不可用,因此我无法使用 Conda 模块安装它:
julia> using Conda
julia> Conda.add("plfit")
[ Info: Running `conda install -y plfit` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- plfit
...
Run Code Online (Sandbox Code Playgroud)
我如何从 Julia 安装这个包?