二进制扩展何时获取文件扩展名'.pyd',何时获取'.so' [英] When does a binary extension gets the file extension '.pyd' and whenis it '.so'

查看:75
本文介绍了二进制扩展何时获取文件扩展名'.pyd',何时获取'.so'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上一切都是''.pyd''但是在unix上似乎有两种方法可以获得



为什么以及规则是什么?< br>

解决方案

llothar写道:


在Windows上一切都是''.pyd''但是似乎有两种方法可以在unix上获得

这个?



如果您尝试导入模块垃圾邮件在Windows上,Python寻找

" spam.dll"和spam.pyd (除了spam.py/spam.pyw/spam.pyc等)


在大多数Unix平台上,Python都会查找spam.so。和spammodule.so。


您可以通过imp

模块检查给定Python版本使用的后缀:


>> import imp
imp.get_suffixes()



要查看*其中* Python的样子,请使用-vv - flag:


python -vv -c" import spam"

...

#reving spam.so

#trying spammodule.so

#trying spam.py

#trying spam.pyc

...等


(-vv打印大量的东西,所以你可能想用grep过滤掉

你的东西''感兴趣:


python -vv -c" import spam" 2>& 1 | grep spam

或在Windows下:


python -vv -c" import spam" 2out.txt

findstr spam out out .txt





为什么以及规则是什么?



如果您希望Python能够导入二进制扩展名,请确保

使用它所查找的名称。


< / F>


On windows everything is ''.pyd'' but there seems to be two ways to get
this on unix?
Why and what is the rule?

解决方案

llothar wrote:

On windows everything is ''.pyd'' but there seems to be two ways to get
this on unix?

If you attempt to import the module "spam" on Windows, Python looks for
"spam.dll" and "spam.pyd" (in addition to "spam.py/spam.pyw/spam.pyc" etc)

On most Unix platforms, Python looks for "spam.so" and "spammodule.so".

You can check what suffixes a given Python version uses via the "imp"
module:

>>import imp
imp.get_suffixes()

To see *where* Python is looking as well, use the "-vv" flag:


python -vv -c "import spam"
...
# trying spam.so
# trying spammodule.so
# trying spam.py
# trying spam.pyc
... etc

(-vv prints loads of stuff, so you may want to use "grep" to filter out
the stuff you''re interested in:


python -vv -c "import spam" 2>&1 | grep spam

or, under Windows:

python -vv -c "import spam" 2out.txt
findstr spam out.txt

)

Why and what is the rule?

If you want Python to be able to import your binary extension, make sure
to use a name it looks for.

</F>


这篇关于二进制扩展何时获取文件扩展名'.pyd',何时获取'.so'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆