我正在开发一个严重依赖 Julia 库的 python 包.我们实际上不是使用 PyCall,而是使用 PackageCompiler.jl
将 Julia 代码编译成共享对象 .so
文件.在 python 模块中使用 ctypes
引用它.它还需要 Julia 系统映像.
I am working on a python package that relies heavily on a Julia library. Rather than use PyCall, we actually compile the Julia code down into shared objects .so
files using PackageCompiler.jl
. It is referenced using ctypes
in the python module. It also requires a Julia systemimage.
有人对如何打包有任何想法吗?我知道您可以在 distutils
中构建 C/C++,但我还没有真正找到跨多个平台包含 Julia 的好地方.
Does anyone have any ideas on how to package this? I know that you can build C/C++ inside of distutils
, but I haven't really found a good venue for including Julia across multiple platforms.
这里要明确一点,对于使用这个 Python 包的人来说,他们需要安装 Julia,并且他们需要适合他们系统的共享对象库.这些可以通过运行 Julia 编译器 juliac.jl
来获得.其他一切都在 Python 中.
To be clear here, for someone to use this Python package they need a Julia installation and they need the appropriate shared object libraries for their system. Those can be gotten by running the Julia compiler juliac.jl
. Everything else is in Python.
假设你使用 setup.py 构建你的库,你需要在调用时将共享库添加到 package_data
setup()
:
Assuming you are using setup.py to build your library, you need to add the shared library(s) to package_data
when calling setup()
:
setup.py
# call out to build system to build the shared library
setup(
name="my-extension",
ext_modules="..."
package_data="/path/to/mylib.so"
)
在此处查看更多文档:https://docs.python.org/3/distutils/setupscript.html#installing-package-data
运行 python setup.py bdist_wheel
创建 .whl 文件后,您可能还想运行 auditwheel,它将兼容性标记(例如 manylinux1)并隔离(用哈希重命名,修复链接)共享库.
After running python setup.py bdist_wheel
to create a .whl file, you may also want to run auditwheel, which will compatibility tag (e.g. manylinux1) and isolate (rename with hash, fix-up linkages) the shared libraries.
这篇关于用编译的 Julia 打包 Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!