Writing setup.py for extension module question

686 views
Skip to first unread message

Uwe Schmitt

unread,
Aug 5, 2011, 5:52:33 AM8/5/11
to cython-users
Hi,

I want to build and install a package which contains a cython based
extension module,
some other python modules and a shared lib.

The interesting part of my setup.py file is:

setup(
name = "pyOpenMS",
ext_package = "pyOpenMS",
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
package_dir = { "pyOpenMS" : "." },
package_data = { "pyOpenMS" : [ "OpenMS.dll" ] },
)

When I run "setup.py install" the extension module "pyOpenMS.pyd" is
copied
to ../site-packages/pyOpenMS.pyd and to ../site-packages/pyOpenMs/
pyOpenMS.pyd.

How can I avoid the installation of ../site-packages/pyOpenMS.pyd ?

Regards, Uwe

Stefan Behnel

unread,
Aug 5, 2011, 6:56:03 AM8/5/11
to cython...@googlegroups.com
Uwe Schmitt, 05.08.2011 11:52:

This isn't a Cython question but a distutils question. In general, it helps
to keep the sources in the same directory structure as the final package.
That would help here, too.

Note that the extension DLL file is *not* package data. It will be
installed as an extension module, and my guess is that you called it
"OpenMS" and not "pyOpenMS.OpenMS".

Stefan

Christopher Barker

unread,
Aug 5, 2011, 12:04:17 PM8/5/11
to cython...@googlegroups.com
On 8/5/11 3:56 AM, Stefan Behnel wrote:
> Uwe Schmitt, 05.08.2011 11:52:
>> I want to build and install a package which contains a cython based
>> extension module,
>> some other python modules and a shared lib.
>>
>> The interesting part of my setup.py file is:
>>
>> setup(
>> name = "pyOpenMS",
>> ext_package = "pyOpenMS",
>> cmdclass = {'build_ext': build_ext},
>> ext_modules = ext_modules,
>> package_dir = { "pyOpenMS" : "." },
>> package_data = { "pyOpenMS" : [ "OpenMS.dll" ] },
>> )
>>
>> When I run "setup.py install" the extension module "pyOpenMS.pyd" is
>> copied
>> to ../site-packages/pyOpenMS.pyd and to ../site-packages/pyOpenMs/
>> pyOpenMS.pyd.
>>
>> How can I avoid the installation of ../site-packages/pyOpenMS.pyd ?

when you specify:

ext_package = "pyOpenMS"

I think you just told distutils to put pyOpenMS.pyd in site-packages.

is pyOpenMS.pyd a package? or is it a module? If it's a module (in the
pyOpenMS package) then you want to specify it in ext_modules. You
haven't given us the definition here, but it might look something like:

ext_modules = [Extension('pyOpenMS.pyOpenMS',
['pyOpenMS.pyx']),
],

By the way this it totally a taste issue, bit I would call the package
"OpenMS", rather than pyOpenMS -- it's a python pacakge after all!

The project itself may be called pyOpenMS in any case -- as I assume
this is a python binding to OpenMS


> Note that the extension DLL file is *not* package data. It will be
> installed as an extension module,

or is the dll a dll that the extension is linked against (the *.pyd is
the extension) in which case, you do need to put it somewhere. Ntoe that
you may have naming issue on other systems -- on *nix shared libs and
python extensions (which are also shared libs) are all called *.so

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Uwe Schmitt

unread,
Aug 5, 2011, 8:24:31 AM8/5/11
to cython-users
Hi,

yes, it is a distutils question. But I found no group or mailing list
focused on distutils, despite the distutils sig group. I will post
my question to stackoverflow, or does anybody have a suggestion where
to ask ? I susspected that my use case is quite typical

I have the Cython sources and the pure Python modules in the same
directory.
Cython builds pyOpenMS.pyd which calls functions from pyOpenMS.dll,
that
is why I declard the dll as package_data.

Regards, Uwe

Uwe Schmitt

unread,
Aug 5, 2011, 11:22:16 AM8/5/11
to cython-users
I found a solution and posted it at:

http://stackoverflow.com/questions/6945969/install-mixture-of-extension-module-pure-python-module-and-shared-libraries-with/6957698#6957698

I think this might be helpful for other cython users.

Uwe

On 5 Aug., 12:56, Stefan Behnel <stefan...@behnel.de> wrote:

Ernesto Posse

unread,
Aug 5, 2011, 1:04:58 PM8/5/11
to cython...@googlegroups.com
On Fri, Aug 5, 2011 at 8:24 AM, Uwe Schmitt <usch...@mineway.de> wrote:
> Hi,
>
> yes, it is a distutils question. But I found no group or mailing list
> focused on distutils, despite the distutils sig group. I will post

The distutils SIG has an active mailing list: (it's the first hit on
Google for "distutils mailing list")

http://mail.python.org/mailman/listinfo/distutils-sig

--
Ernesto Posse

Modelling and Analysis in Software Engineering
School of Computing
Queen's University - Kingston, Ontario, Canada

Christopher Barker

unread,
Aug 5, 2011, 2:26:17 PM8/5/11
to cython...@googlegroups.com
On 8/5/11 5:24 AM, Uwe Schmitt wrote:
> Cython builds pyOpenMS.pyd which calls functions from pyOpenMS.dll,
> that
> is why I declard the dll as package_data.

note: this is dangerous -- they really should have different names,
asside from the extension.

There was a bunch of discussion about this on this list a while back,
and while it's appealing to do it this way, trust me when I say: don't
to it.

-Chris

Uwe Schmitt

unread,
Aug 6, 2011, 4:53:05 AM8/6/11
to cython-users

Yes, I knew that. But it is not "distutil users", which I was looking
for.
AFAIK the distutils sig is for distutil developers....
I thought my question would better fit into this group.

Regards, Uwe

On 5 Aug., 19:04, Ernesto Posse <epo...@gmail.com> wrote:

Uwe Schmitt

unread,
Aug 6, 2011, 4:53:47 AM8/6/11
to cython-users
Thanks. I will change that.
Regrads, Uwe
> Chris.Bar...@noaa.gov
Reply all
Reply to author
Forward
0 new messages