如何"安装"自定义的Python模块由Boost.Python的制作 [英] how to "install" custom python module made by boost.python
问题描述
我与一个Boost.Python的的.so
模块,可以从本地文件夹导入。
I have made a .so
module with boost.python and can import it from local folder.
|--my_class.so
|--python_code.py
在python_ code.py
in python_code.py
from my_class import *
显然,如果我把 python_ code.py
在不同的文件夹,从my_class进口*
会失败。
Obviously if I put python_code.py
in a different folder, from my_class import *
would fail.
我想知道是否存在这样我可以从任何Python脚本导入一个gobal包的位置,我可以安装 my_class.so
的一种方式。因此, my_class
具有同等的地位像 numpy的
包。
I am wondering if there is a way that I can "install" my_class.so
in a gobal package location that I can import it from any python script. So my_class
has the same status as packages like numpy
.
推荐答案
您应该能够移动的.so文件的地方你的Python库路径上。在我的机器的一个例子是目录/usr/lib/python2.7
You should be able to move the .so file somewhere on your python library path. On my machine one example is the directory /usr/lib/python2.7
您可以考虑这样做的一个方法是使用一个setup.py文件,它可以被配置来处理您的构建和安装。
One way you might consider doing this is with a setup.py file, which can be configured to handle your build and install.
在过去,我有时只是把它抄了没有,用手测试或把一些诸如以下,进入一个Makefile所以它拷贝编译后:
In the past I've sometimes just copied it there by hand for testing or put a something such as below into a Makefile so it copies after compile:
#
# Install the python module
#
install: /usr/local/lib/python2.7/dist-packages/MyModule.so
/usr/local/lib/python2.7/dist-packages/MyModule.so: python-module
cp $(BIN)MyModule.so /usr/local/lib/python2.7/dist-packages/MyModule.so
这篇关于如何"安装"自定义的Python模块由Boost.Python的制作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!