Re: How does setup.py work?



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

.



Relevant Pages

  • Creating an RPM which works with multiple Python versions?
    ... some C-coded extension modules. ... The app works fine with Python ... However I've noticed that the RPM installs ... Somehow convince RPM to install the extensions to the directory for ...
    (comp.lang.python)
  • Re: distutils on Win32 using .NET Framework SDK
    ... The extension worked on Cygwin but when I ... > tried it with the Win32-build python, ... > that I don't have .NET Framework SDK installed. ... Not sure why you are trying to install .NET 2.0, ...
    (comp.lang.python)
  • Re: distutils on Win32 using .NET Framework SDK
    ... The extension worked on Cygwin but when I ... > tried it with the Win32-build python, ... > that I don't have .NET Framework SDK installed. ... Not sure why you are trying to install .NET 2.0, ...
    (comp.lang.python)
  • Re: PY2EXE - Strange Things a-Happenin
    ... > So I've been playing with Python and Pygame for a while and I decided ... > #setup the project variables here. ... "python setup.py py2exe"?? ...
    (comp.lang.python)
  • Re: Newbie question: Multiple installations of Python on Windows machines
    ... be able to open it using winzip or winrar and do a manual install. ... You can then install Python ... So I tried this and copied the files from my virtual machine to the site-packages folder on my real Python 2.4 machine, I then ran into there being a compiled extension. ...
    (comp.lang.python)