[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

How does setup.py work?

dxm

12/19/2007 8:16:00 AM

I am a new comer to python.
I am wondering how setup.py works.
For example, I have a directory like this:
/
setup.py
mymodule.c

where setup.py is:

from distutils.core import setup, Extension

mod = Extension('mymodule', sources = ['mymodule.c'])

setup (name = 'Package',
version = '1.0',
description = 'This is a demo package',
ext_modules = [mod])

The correct way to install the newly created extension module is to
type
python setup.py install instead of executing those statements in
python shell, isn't it ?
My question is how additional arguments like 'build', 'install' are
passed into python and how
can I install it from interactively from python shell

3 Answers

Matias Surdi

12/19/2007 8:37:00 AM

0

dxm escribió:
> I am a new comer to python.
> I am wondering how setup.py works.
> For example, I have a directory like this:
> /
> setup.py
> mymodule.c
>
> where setup.py is:
>
> from distutils.core import setup, Extension
>
> mod = Extension('mymodule', sources = ['mymodule.c'])
>
> setup (name = 'Package',
> version = '1.0',
> description = 'This is a demo package',
> ext_modules = [mod])
>
> The correct way to install the newly created extension module is to
> type
> python setup.py install instead of executing those statements in
> python shell, isn't it ?
> My question is how additional arguments like 'build', 'install' are
> passed into python and how
> can I install it from interactively from python shell
>


Here you can read the documentation of "setuptools" , the package from
where setup.py comes.

http://peak.telecommunity.com/DevCenter/...

Robert Kern

12/19/2007 9:12:00 AM

0

Matias Surdi wrote:

> Here you can read the documentation of "setuptools" , the package from
> where setup.py comes.
>
> http://peak.telecommunity.com/DevCenter/...

No, setup.py files are standard distutils. setuptools is a 3rd-party package
that extends distutils.

http://docs.python.org/dist...

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Robert Kern

12/19/2007 9:17:00 AM

0

dxm wrote:
> I am a new comer to python.
> I am wondering how setup.py works.
> For example, I have a directory like this:
> /
> setup.py
> mymodule.c
>
> where setup.py is:
>
> from distutils.core import setup, Extension
>
> mod = Extension('mymodule', sources = ['mymodule.c'])
>
> setup (name = 'Package',
> version = '1.0',
> description = 'This is a demo package',
> ext_modules = [mod])
>
> The correct way to install the newly created extension module is to
> type
> python setup.py install instead of executing those statements in
> python shell, isn't it ?

Yes.

> My question is how additional arguments like 'build', 'install' are
> passed into python

Command-line arguments are passed into Python as the list sys.argv. Try running
the following script to explore this:

#### sys_argv.py ####
#!/usr/bin/env python
import sys
print sys.argv
#####################

[~]$ python sys_argv.py
['sys_argv.py']
[~]$ python sys_argv.py build
['sys_argv.py', 'build']
[~]$ python sys_argv.py build_ext --inplace install
['sys_argv.py', 'build_ext', '--inplace', 'install']

http://docs.python.org/lib/modul...

Code inside setup() parses this list to determine what actions the user wants it
to take.

> and how
> can I install it from interactively from python shell

Generally speaking, you don't. distutils was not really designed for this use
case. There is no easy way to do this.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco