Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55386

Re: Running code from source that includes extension modules

From Michael Schwarz <michi.schwarz@gmail.com>
Subject Re: Running code from source that includes extension modules
Date 2013-10-03 00:28 +0200
References <CABdB9Z4rvKmO0bdZrmBd4Cy6b1OJyzkFMNpwmrR=k55J1X39wg@mail.gmail.com> <l2hrbf$uc9$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.656.1380752882.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 2013-W40-3, at 21:15, Stefan Behnel <stefan_ml@behnel.de> wrote:

> Michael Schwarz, 02.10.2013 17:38:
>> I've just started looking into distutils because I need to write an
>> extension module in C (for performance reasons) and distutils seems to be
>> the most straight-forward way.
>> 
>> I've had success building a C file into a Python extension module using
>> "python setup.py build" but I am wondering what the recommended way for
>> using that module during development is. While writing Python code I'm used
>> to just run the code from the source directory. But the built extension
>> module's .so of course does not just end up on sys.path magically.
>> 
>> So how do I run my code so it will find the built extension module? Do I
>> pass the output directory on the command line manually or is there some
>> other solution? I would like to still be able to run the code from the
>> source directory as I'm using PyCharm to edit and debug the code.
> 
> You can run
> 
> 	python setup.py build_ext -i
> 
> That will build your extension module and install it right into your
> package structure.

This is really very much what I was looking for! I've set up PyCharm to run this command (by configuring it as an "external tool", maybe there's a simpler way), before running the actual application. \o/

> BTW, if you use Cython instead of plain C, you can use pyximport to get
> on-the-fly extension module builds during development.

I will look into that too, that sounds very convenient. But am I right, that to use Cython the non-Python code needs to be written in the Cython language, which means I can't just copy&past C code into it? For my current project, this is exactly what I do, because the C code I use already existed.

Thanks
Michael

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Running code from source that includes extension modules Michael Schwarz <michi.schwarz@gmail.com> - 2013-10-03 00:28 +0200

csiph-web