471,330 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

How does setup.py work?

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

Dec 19 '07 #1
1 3247
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/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

Dec 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by paul kölle | last post: by
1 post views Thread by Wendy Elizabeth | last post: by
1 post views Thread by Chris | last post: by
1 post views Thread by Wendy Elizabeth | last post: by
2 posts views Thread by Martin Kulas | last post: by
6 posts views Thread by Christof Nordiek | last post: by
1 post views Thread by =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.