Monday, March 30, 2009

Read code to find the source of your problems

On my previous blog post, I commented that I wanted to install mercurial in one of our school servers (in which I have no privileges) and what it was a success last week it has become problematic in this second time.

I tried to build and I got this:
azambran@matrix:~/sources/mercurial-1.2.1> python build
running build
running build_py
running build_ext
error: invalid Python installation: unable to open /usr/lib/python2.5/config/Makefile (No such file or directory)
I looked for the string: "invalid Python installation: unable to open" and found the file "/usr/lib/python2.5/distutils/", I found the string :
def _init_posix():
"""Initialize the module as appropriate for POSIX systems."""
g = {}
# load the installed Makefile:
filename = get_makefile_filename()
parse_makefile(filename, g)
except IOError, msg:
my_msg = "invalid Python installation: unable to open %s" % filename
if hasattr(msg, "strerror"):
my_msg = my_msg + " (%s)" % msg.strerror

raise DistutilsPlatformError(my_msg)
which lead me here:
def get_makefile_filename():
"""Return full pathname of installed Makefile from the Python build."""
if python_build:
return os.path.join(os.path.dirname(sys.executable), "Makefile")
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
return os.path.join(lib_dir, "config", "Makefile")
I am leaving this blog post and will follow it up with comments in case somebody needs the solution to this problem.

The main goal of this post is to show that even if you have no clue about the code that you are using you can still reach the internals of a large code base. Following this approach will help others who might want to help you and help you narrowing down the questions that you ask.

Creative Commons License
This work by Zambrano Gasparnian, Armen is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.


  1. You can set the environment variable DISTUTILS_DEBUG=1 to get a little more information.

    I think that Makefile is supposed to be installed when you build and install Python. Each of the Python installations on my Mac has one, anyway.

  2. Thanks jto, I had the same discussions earlier on IRC, it makes no sense that the config/Makefile does not exist; Maybe the system administrators removed something?

    I will use what you tell me and see how it goes.