Python、SWIG 和其他奇怪的东西

发布于 2024-08-25 01:32:08 字数 2160 浏览 6 评论 0原文

我有一个 USB 模块的固件,我已经可以通过 Visual C 控制。现在我想将其移植到 python 中。为此,我需要用 c 编写的 octopus 库。我发现了一个名为 octopus_wrap 的文件,它是由 SWIG 创建的!

然后我找到了一个 makefile,上面写着:

python2.5: swig -python -outdir ./ ../octopus.i gcc -fPIC -c ../../liboctopus/src/octopus.c gcc -fPIC -c ../octopus_wrap.c -I /usr/include/python2.5 gcc -fPIC -shared octopus_wrap.o octopus.o /usr/lib/libusb.so -o _octopus.so

python2.4: swig -python -outdir ./ ../octopus.i gcc -fPIC -c ../../liboctopus/src/octopus.c gcc -fPIC -c ../octopus_wrap.c -I /usr/include/python2.4 gcc -fPIC -shared octopus_wrap.o octopus.o /usr/lib/libusb.so -o _octopus.so

获胜: gcc -fPIC -c ../../liboctopus/src/octopus.c -I /c/Programme/libusb-win32-device-bin-0.1.10.1/include gcc -fPIC -c octopus_wrap.c -I /c/Python25/libs -lpython25 -I/c/Python25/include -I /c/Programme/libusb-win32-device-bin-0.1.10.1/include gcc -fPIC -shared *.o -o _octopus.pyd -L/c/Python25/libs -lpython25 -lusb -L/c/Programme/libusb-win32-device-bin-0.1.10.1/lib/gcc

干净: rm -f 章鱼* _章鱼*

安装_python2.4: cp _octopus.so /usr/local/lib/python2.4/site-packages/ cp octopus.py /usr/local/lib/python2.4/site-packages/

安装_python2.5: cp _octopus.so /usr/local/lib/python2.5/site-packages/ cp octopus.py /usr/local/lib/python2.5/site-packages/

我不知道如何处理这个问题,但据我所知 octopus.py 和 _octopus.so 是与 python 相关的结果输出文件正确的?

幸运的是,有人已经这样做了,所以我将这两个文件放入我的“python26/lib”文件夹中(希望它是 python 2.5 还是 2.6 并不重要?!)

所以当使用 USB 设备时,octopus.py 是库一起工作! 导入此文件会产生几个问题:

>>> 
Traceback (most recent call last):
File "C:\Users\ameise\My Dropbox\µC\AVR\OCTOPUS\octopususb-0.5\demos\python    \blink_status.py", line 8, in <module>
from  octopus import *
File "C:\Python26\lib\octopus.py", line 7, in <module>
import _octopus
ImportError: DLL load failed: module not found.

这是相关的第 7 行:

import _octopus

所以考虑到 .so 文件存在问题! 我的下一步可能是什么?

我知道这有很多令人困惑的事情,但我希望你们中的任何人都能给我带来一些启发!

你提前

I have a firmware for an USB module I can already control by visual C. Now I want to port this to python. for this I need the octopus library which is written in c. I found a file called octopus_wrap which was created by SWIG!

then I found a makefile which says:

python2.5:
swig -python -outdir ./ ../octopus.i
gcc -fPIC -c ../../liboctopus/src/octopus.c
gcc -fPIC -c ../octopus_wrap.c -I /usr/include/python2.5
gcc -fPIC -shared octopus_wrap.o octopus.o /usr/lib/libusb.so -o _octopus.so

python2.4:
swig -python -outdir ./ ../octopus.i
gcc -fPIC -c ../../liboctopus/src/octopus.c
gcc -fPIC -c ../octopus_wrap.c -I /usr/include/python2.4
gcc -fPIC -shared octopus_wrap.o octopus.o /usr/lib/libusb.so -o _octopus.so

win:
gcc -fPIC -c ../../liboctopus/src/octopus.c -I /c/Programme/libusb-win32-device-bin-0.1.10.1/include
gcc -fPIC -c octopus_wrap.c -I /c/Python25/libs -lpython25 -I/c/Python25/include -I /c/Programme/libusb-win32-device-bin-0.1.10.1/include
gcc -fPIC -shared *.o -o _octopus.pyd -L/c/Python25/libs -lpython25 -lusb -L/c/Programme/libusb-win32-device-bin-0.1.10.1/lib/gcc

clean:
rm -f octopus* _octopus*

install_python2.4:
cp _octopus.so /usr/local/lib/python2.4/site-packages/
cp octopus.py /usr/local/lib/python2.4/site-packages/

install_python2.5:
cp _octopus.so /usr/local/lib/python2.5/site-packages/
cp octopus.py /usr/local/lib/python2.5/site-packages/

I dont know how to handle this but as far as I can see octopus.py and _octopus.so are the resulting output files which are relevant to python right?

luckily someone already did that and so I put those 2 files to my "python26/lib" folder (hope it doesnt matter if it´s python 2.5 or 2.6?!)

So when working with the USB device the octopus.py is the library to work with!
Importing this file makes several problems:

>>> 
Traceback (most recent call last):
File "C:\Users\ameise\My Dropbox\µC\AVR\OCTOPUS\octopususb-0.5\demos\python    \blink_status.py", line 8, in <module>
from  octopus import *
File "C:\Python26\lib\octopus.py", line 7, in <module>
import _octopus
ImportError: DLL load failed: module not found.

and here´s the related line 7 :

import _octopus

So there´s a problem considering the .so file!
What could be my next step?

I know that´s a lot of confusing stuff but I hope anyone of you could bring some light in my mind!

thy in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-09-01 01:32:08

您应该链接并编译 python2.6 -lpython26
Windows 的文件扩展名是 .pyd 而不是 .so

You should link and compile for the python2.6 -lpython26.
Also the file extension for windows is .pyd no .so

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文