Importing a .pyd (created with SWIG) in Python 2.7.3 on Mac

ⅰ亾dé卋堺 提交于 2021-01-27 13:41:48

问题


I have created a .pyd file with SWIG under Windows named (_example.pyd).

I am able to send the file to my email and import it with another Windows machine using the same version of Python (Python 2.7.3) with this simple command:

.>>> import _example

.>>>

But when I send it to my email and tried to import the file with a Mac, I get:

"No module named _example"

Any ideas?

In both cases, I saved the file into the Python path.


回答1:


This is because Python extensions (.pyd files) are essentially DLLs.
If you want to use your extension on a Mac, you will need to compile it for/on a Mac.

http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll




回答2:


I once had the same error for a different reason: I had built the module from source, except I assumed ".pyd" to be a universal extension (be it a DLL or an ELF shared object), so I told gcc to create "mymodule.pyd" instead of "mymodule.so": on both Linux and Windows, the contents of the file were correct once compiled, but the name was only valid on Windows.

On Linux, a simple mv mymodule.pyd mymodule.so solved it.



来源:https://stackoverflow.com/questions/11866288/importing-a-pyd-created-with-swig-in-python-2-7-3-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!