How does setup.py work?

D

dxm

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
 
M

Matias Surdi

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/setuptools
 
R

Robert Kern

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

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

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

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

--
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
 
R

Robert Kern

dxm said:
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/module-sys.html

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,198
Latest member
JaimieWan8

Latest Threads

Top