[Numpy-discussion] numscons and Python 2.7 problems

Christoph Gohlke cgohlke at uci.edu
Mon Jun 7 16:07:04 EDT 2010


Dear NumPy developers,

I was trying to build numpy 2.0.dev and scipy 0.9.dev using numscons 
0.12.dev and Python 2.7b2 (32 bit) on Windows 7 64 bit and ran into two 
problems.


First, Python 2.7's UserDict is now a new-style class 
(http://docs.python.org/dev/whatsnew/2.7.html). Apparently scons 1.2, 
which is part of numscons, is not compatible with this change and an 
AttributeError is thrown:

AttributeError: NumpyEnvironment instance has no attribute 'SubstInFile':
   File "D:\numpy-trunk\numpy\core\SConstruct", line 2:
     GetInitEnvironment(ARGUMENTS).DistutilsSConscript('SConscript')
   File "C:\Python27\lib\site-packages\numscons\core\numpyenv.py", line 135:
     build_dir = '$build_dir', src_dir = '$src_dir')
   File 
"C:\Python27\lib\site-packages\numscons\scons-local\scons-local-1.2.0\SCons\Script\SConscript.py", 
line 553:
     return apply(_SConscript, [self.fs,] + files, subst_kw)
   File 
"C:\Python27\lib\site-packages\numscons\scons-local\scons-local-1.2.0\SCons\Script\SConscript.py", 
line 262:
     exec _file_ in call_stack[-1].globals
   File "D:\numpy-trunk\build\scons\numpy\core\SConscript", line 353:
     target = env.SubstInFile(pjoin(include_dir, '_numpyconfig.h'),

Turns out that the env['BUILDERS'] dictionary is empty after the 
config.Finish() call in SConscript. A workaround is to copy the 
UserDict.py file from Python27\Lib to 
numscons\scons-local\scons-local-1.2.0\SCons and change UserDict back to 
an old-style class:

@@ -1,6 +1,6 @@
  """A more or less complete user-defined wrapper around dictionary 
objects."""

-class UserDict(object):
+class UserDict:
      def __init__(self, dict=None, **kwargs):
          self.data = {}
          if dict is not None:
@@ -80,10 +80,7 @@
      def __iter__(self):
          return iter(self.data)

-import _abcoll
-_abcoll.MutableMapping.register(IterableUserDict)

-
  class DictMixin:
      # Mixin defining all dictionary methods for classes that already have
      # a minimum dictionary interface including getitem, setitem, delitem,



Second, when Python 2.7 is run on a 64 bit host, sys.platform.machine() 
is 'AMD64' even if Python is 32 bit (http://bugs.python.org/issue7860). 
Hence numscons always uses the win64 configuration on Python 2.7. This 
can be fixed by using "if '64 bit' in sys.version" or 
"platform.architecture()[0] == '64bit'" instead of "platform.machine() 
== 'AMD64'":

diff --git a/numscons/checkers/config.py b/numscons/checkers/config.py
index 4ca1079..198ccdb 100644
--- a/numscons/checkers/config.py
+++ b/numscons/checkers/config.py
@@ -18,7 +18,7 @@ def _get_win32_config_files():
      import platform

      files = [pjoin(_CONFDIR, 'win32', 'perflib.cfg')]
-    if platform.machine() == 'AMD64':
+    if platform.architecture()[0] == '64bit':
          files.append(pjoin(_CONFDIR, 'win64', 'perflib.cfg'))
      return files


diff --git a/numscons/core/compiler_config.py 
b/numscons/core/compiler_config.py
index d6a79d9..606963e 100644
--- a/numscons/core/compiler_config.py
+++ b/numscons/core/compiler_config.py
@@ -29,7 +29,7 @@ def _get_win32_config_files(filename):
      import platform

      files = [pjoin(_CONFDIR, 'win32', filename)]
-    if platform.machine() == 'AMD64':
+    if platform.architecture()[0] == '64bit':
          files.append(pjoin(_CONFDIR, 'win64', filename))
      return files

diff --git a/numscons/core/misc.py b/numscons/core/misc.py
index a546122..42836b9 100644
--- a/numscons/core/misc.py
+++ b/numscons/core/misc.py
@@ -59,7 +59,7 @@ def built_with_ifort(env):
  def is_python_win64():
      # XXX: import it here because it takes some time
      import platform
-    return sys.platform == "win32" and platform.machine() == "AMD64"
+    return sys.platform == "win32" and platform.architecture()[0] == 
'64bit'

  def get_pythonlib_name(debug = 0):
      """Return the name of python library (necessary to link on NT with


--
Christoph



More information about the NumPy-Discussion mailing list