By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

When does a binary extension gets the file extension '.pyd' and whenis it '.so'

P: n/a
On windows everything is '.pyd' but there seems to be two ways to get
this on unix?
Why and what is the rule?
Apr 4 '08 #1
Share this Question
Share on Google+
13 Replies


P: n/a
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>

Apr 4 '08 #2

P: n/a
llothar wrote:
My question was: Why does setup.py generated sometimes a pyd and
sometimes a so file?
setup.py picks an extension that happens to work on the platform you're
running setup.py on. doing otherwise would be pretty pointless.

</F>

Apr 5 '08 #3

P: n/a
llothar wrote:
I ship an application that compiles an python interpreter and
extension on a remote system.
It also needs to copy this created items around. So if i use setup.py
to create an
extension i need to know the file name of the generated file.
so why not just ask setup.py to copy the files for you?

you can either use "install" with the --home option to copy all the
files to a given directory, or create a binary kit with "bdist" and
unpack the resulting archive at the target location.
Unfortunately as pointless as the answers i got so far.
well, cutting the "I'm not going to tell you why I need to know this"
stuff might help people come up with solutions to your actual problem
instead of posting stuff that's informative but misses the point.

</F>

Apr 5 '08 #4

P: n/a
Right, so you think people aren't trying to help you?

I think they are not reading the question.
You display your ignorance here. The ".pyd" extension is used on Windows
as an alternative to ".dll", but both are recognized as shared
libraries. Personally I'm not really sure why they even chose to use
".pyd", which is confusing to most Windows users.
Here i agree. But having it's own identifiying extension has also some
small benefits.
To depart from the platform standard would be unhelpful and confusing to
the majority of users. It's know use telling us what you think: tell us
instead the compelling reasons why your opinion is correct. Opinions,
after all, are so cheap that everyone can have one.
Because i want a uniform solution. Either use "dllso" or use "pyd"
but
stay with one decision once made. At the moment when i build python on
my ubuntu system without "--enable-shared" i get a pyd file created,
if
i use "--enable-shared" it is a so file.

I don't know if this is a special case on Linux or the general on unix
systems
(i only have Linux, FreeBSD, NetBSD, OpenBSD, Solaris and MacOSX in
mind).
There are ways to build distributions of Python extensions (modules or
packages involving binary code from languages like C or C++), but you
will want to understand a bit more about computing in general
Believe me nobody needs to teach me anything about general programming
anymore.
(and work on your social skills ;-)
I don't think so. I asked a pretty simple question and as usual on
usenet nobody
read the question but answered to complete different topics. Answers
on usenet are
so cheap, everybody likes to give one - no matter if it is ontopic,
right or wrong.
And this does not really help.

My question is simple and person who knows setup.py and distools would
be able to
give the answer in a small sentence if there is a strategy behind it
and it's not
only a bug.

Unfortunately there is no python.core mailing list that i know so i
ask here.
Apr 5 '08 #5

P: n/a
llothar wrote:
I don't think so. I asked a pretty simple question and as usual on
usenet nobody read the question
did *you* read your own question? it took you three posts before you
mentioned what you were trying to do, and four posts before you bothered
to mention that you're seeing this behaviour on Ubuntu.

and for the record, Python doesn't look for PYD files on any of the Unix
boxes I have convenient access to right now. what Ubuntu version are
you using, what Python version do you have, and what does

$ python -c "import imp; print imp.get_suffixes()"

print on your machine?

</F>

Apr 5 '08 #6

P: n/a
llothar wrote:
[...]
Unfortunately there is no python.core mailing list that i know so i
ask here.
Well your researches can't have been that extensive: the developers live
on python-dev@pythonlorg, otherwise known as comp.land.python-dev. But
you will need to ask your question rather more carefully there to het a
meaningful answer. Good luck.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Apr 5 '08 #7

P: n/a
Fredrik Lundh wrote:
and for the record, Python doesn't look for PYD files on any of the Unix
boxes I have convenient access to right now. what Ubuntu version are
you using, what Python version do you have, and what does

$ python -c "import imp; print imp.get_suffixes()"

print on your machine?
for reference, here's what I get on Ubuntu 7.10, with the standard
Python interpreter (2.5.1):

$ python -c "import imp; print imp.get_suffixes()"
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1),
('.pyc', 'rb', 2)]

any Ubuntu gurus here that can sort this one out?

</F>

Apr 5 '08 #8

P: n/a
There must be a rule behind this.

There are multiple rules behind this. Python normally uses
the same extension for shared libraries as the operating
system, as the operating system may refuse to load them if
it doesn't. So it *can't* use .pyd on Unix, because that
might not work (on some implementations of Unix).

It can't use .dll on Windows, because that may (and did)
conflict with existing DLLs, hence it uses .pyd.

Depending on the system, an extension module may have one
of these suffixes:
- .so
- module.so
- .sl
- module.sl
- .exe
- .EXE
- module.exe
- module.EXE
- .pyd
- _d.pyd

Regards,
Martin
Apr 5 '08 #9

P: n/a
Fredrik Lundh wrote:
Fredrik Lundh wrote:
>and for the record, Python doesn't look for PYD files on any of the Unix
boxes I have convenient access to right now. what Ubuntu version are
you using, what Python version do you have, and what does

$ python -c "import imp; print imp.get_suffixes()"

print on your machine?

for reference, here's what I get on Ubuntu 7.10, with the standard
Python interpreter (2.5.1):

$ python -c "import imp; print imp.get_suffixes()"
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1),
('.pyc', 'rb', 2)]

any Ubuntu gurus here that can sort this one out?
I wouldn't claim to be an Ubuntu guru but it seems as though the Ubuntu
team decide that you would be able to import extension module YYY either
from YYY.so or from YYYmodule.so. IF you are asking *why* then I'd have
to answer that I have no idea at all.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Apr 6 '08 #10

P: n/a
Fredrik Lundh wrote:
Fredrik Lundh wrote:
>and for the record, Python doesn't look for PYD files on any of the Unix
boxes I have convenient access to right now. what Ubuntu version are
you using, what Python version do you have, and what does

$ python -c "import imp; print imp.get_suffixes()"

print on your machine?

for reference, here's what I get on Ubuntu 7.10, with the standard
Python interpreter (2.5.1):

$ python -c "import imp; print imp.get_suffixes()"
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1),
('.pyc', 'rb', 2)]

any Ubuntu gurus here that can sort this one out?
I wouldn't claim to be an Ubuntu guru but it seems as though the Ubuntu
team decide that you would be able to import extension module YYY either
from YYY.so or from YYYmodule.so. IF you are asking *why* then I'd have
to answer that I have no idea at all.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Apr 6 '08 #11

P: n/a
Steve Holden wrote:
>for reference, here's what I get on Ubuntu 7.10, with the standard
Python interpreter (2.5.1):

$ python -c "import imp; print imp.get_suffixes()"
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1),
('.pyc', 'rb', 2)]

any Ubuntu gurus here that can sort this one out?
I wouldn't claim to be an Ubuntu guru but it seems as though the Ubuntu
team decide that you would be able to import extension module YYY either
from YYY.so or from YYYmodule.so. IF you are asking *why* then I'd have
to answer that I have no idea at all.
oh, the ".so" and "module.so" is standard Python behaviour (see my first
post in this thread). what I cannot figure out is how "llothar" has
managed to get setup.py to build extensions that an Ubuntu Python cannot
load, without noticing.

</F>

Apr 6 '08 #12

P: n/a
llothar schreef:
>There are ways to build distributions of Python extensions (modules or
packages involving binary code from languages like C or C++), but you
will want to understand a bit more about computing in general

Believe me nobody needs to teach me anything about general programming
anymore.
"The people who are best at programming are the people who realize how
small their brains are. They are humble." -- Edsger Dijkstra, 1972

(http://www.codinghorror.com/blog/archives/000051.html,
http://www.cs.utexas.edu/users/EWD/ewd03xx/EWD340.PDF)
--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
-- Isaac Asimov

Roel Schroeven
Apr 6 '08 #13

P: n/a
Fredrik Lundh wrote:
Steve Holden wrote:
>>for reference, here's what I get on Ubuntu 7.10, with the standard
Python interpreter (2.5.1):

$ python -c "import imp; print imp.get_suffixes()"
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1),
('.pyc', 'rb', 2)]

any Ubuntu gurus here that can sort this one out?
I wouldn't claim to be an Ubuntu guru but it seems as though the Ubuntu
team decide that you would be able to import extension module YYY either
from YYY.so or from YYYmodule.so. IF you are asking *why* then I'd have
to answer that I have no idea at all.

oh, the ".so" and "module.so" is standard Python behaviour (see my first
post in this thread). what I cannot figure out is how "llothar" has
managed to get setup.py to build extensions that an Ubuntu Python cannot
load, without noticing.
Well, at least *I* learned something in this thread. I had missed that
second paragraph in your first post, and hadn't realised it from other
sources.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Apr 7 '08 #14

This discussion thread is closed

Replies have been disabled for this discussion.