[PEAK] Setting Up PEAK

Phillip J. Eby pje at telecommunity.com
Mon Oct 11 15:49:54 EDT 2004


At 11:25 AM 10/11/04 -0700, Bernard Putersznit wrote:
>PEAK Folks:
>
>First, please forgive my newbie status with Python and
>PEAK, and any clumsiness on my part.
>
>I'm trying to intall PEAK on my Toshiba Sattelite
>Laptop, running WinXP Professional.  The Tar ball
>unzips into C:\PEAK just fine. However, when I run
>SETUP.PY it complains about:
>
>C:\PEAK-0.5a3>c:\python23\python
>c:\peak-0.5a3\setup.py install
>running install
>running build
>running build_py
>running build_ext
>error: Python was built with version 6 of Visual
>Studio, and extensions need to
>be built with the same version of the compiler, but it
>isn't installed.
>
>It seems that this script is trying to re-install
>Python itself and not peak.

No, it's trying to build the Python extensions that PEAK needs.  If you 
don't have the Visual Studio C compiler available (and apparently you 
don't), you'll need to follow these instructions:

http://twistedmatrix.com/pipermail/twisted-python/2004-February/007205.html

The step described as "c) build a 'libpython2x.a' library", can be 
accomplished by running the following script:

# --- script begins ---
"""Create pythonNN.def and libpythonNN.a in 'PythonNN/libs' directory

This script makes it possible to use the MinGW compiler tools to
build C extensions that work with the standard Windows Python
distribution.

Before running, you should have installed the MinGW compiler toolset,
and placed its 'bin' directory on your PATH.  An easy way to do this
is to install Cygwin's "binutils", "gcc", and "mingw-*" packages,
then run this script from the Cygwin shell.  (Be sure to use *Windows*
Python, not Cygwin Python!)

Once this script has been run, you should be able to build extensions
using distutils in the standard way, as long as you select the
'mingw32' compiler, and the required tools are on your PATH.  See
the "Installing Python Modules" manual for more information on
selecting a compiler.
"""

from distutils.spawn import find_executable
from distutils.sysconfig import get_config_var
from distutils import __file__ as distutils_file
import os, re, sys

if sys.platform=='cygwin':
     print "Please run this script using Windows python,",
     print "not Cygwin python.  E.g, try:"
     print
     print "/cygdrive/c/PythonNN/python", " ".join(sys.argv)
     print
     print "(where NN is the major/minor python version number)"
     sys.exit()

basename = 'python%d%d' % sys.version_info[:2]

libs_dir = os.path.join(get_config_var('prefix'),'libs')
lib_file = os.path.join(libs_dir,basename+'.lib')
def_file = os.path.join(libs_dir,basename+'.def')
ming_lib = os.path.join(libs_dir,'lib%s.a' % basename)

distutils_cfg = os.path.join(os.path.dirname(distutils_file),'distutils.cfg')

export_match = re.compile(r"^_imp__(.*) in python\d+\.dll").match

nm      = find_executable('nm')
dlltool = find_executable('dlltool')

if not nm or not dlltool:
     print "'nm' and/or 'dlltool' were not found;"
     print "Please make sure they're on your PATH."
     sys.exit()

nm_command = '%s -Cs %s' % (nm, lib_file)

print "Building", def_file, "using", nm_command
f = open(def_file,'w')
print >>f, "LIBRARY %s.dll" % basename
print >>f, "EXPORTS"


nm_pipe = os.popen(nm_command)
for line in nm_pipe.readlines():
     m = export_match(line)
     if m:
         print >>f, m.group(1)
f.close()

exit = nm_pipe.close()
if exit:
     print "nm exited with status", exit
     print "Please check that", lib_file, "exists and is valid."
     sys.exit()

dt_cmd = "%s --dllname %s.dll --def %s --output-lib %s" % (
     dlltool, basename, def_file, ming_lib
)

print "Building",ming_lib,"using",dt_cmd

dlltool_pipe = os.popen(dt_cmd)
dlltool_pipe.readlines()
exit = dlltool_pipe.close()
if exit:
     print "dlltool exited with status", exit
     print "Unable to proceed."
     sys.exit()

print
print "Installation complete.  You may wish to add the following"
print "lines to", distutils_cfg, ':'
print
print "[build]"
print "compiler = mingw32"
print
print "This will make the distutils use MinGW as the default"
print "compiler, so that you don't need to configure this for"
print "every 'setup.py' you run."
# --- script ends ---


Once you've done this on a given machine, you'll be able to build any 
Windows-compatible Python extensions without needing Visual C.  If you 
upgrade to a newer version of Python, you'll need to rerun the script (and 
edit the new distutils.cfg file) using the newer version, since the stuff 
it builds is specific to a particular Python version.





More information about the PEAK mailing list