Python、SWIG 和其他奇怪的东西
我有一个 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.sopython2.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.sopython2.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.sowin:
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/gccclean:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该链接并编译 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