You are not logged in Log in Join
You are here: Home » Members » Jens Vagelpohl » Documentation » Zope and Python on Mac OS X » View Document

Log in
Name

Password

 

Zope and Python on Mac OS X

How to build Python and Zope on Mac OS X

Building Python and Zope on Mac OS X 10.1 and higher

If you just upgraded to OS X version 10.2 and now your Python binary and Zope fail with cryptic error messages then simply rebuild them using the steps outlined below. This will solve the problem.

This document explains how to build Python and Zope on Mac OS X version 10.1 and up. If you are running an earlier Mac OS X version before 10.1 you should turn to Jeffrey Shell's HowTo at /Members/jshell/ZopeOnOSX.

Tested Software Versions

  • Python 2.1.3
  • Python 2.2.x, 2.3.x,2.4.x
  • Zope 2.4 through 2.9 series

Keep in mind that Zope up to version 2.6.2 requires Python 2.1.3 and Zope 2.7 as well as 2.8 require Python 2.3.5. Zope 2.9 and on run on Python 2.4.x. OS X version 10.2 and up already has Python installed (10.2 has Python 2.2.2, 10.3 comes with Python 2.3.0 and 10.4 brings Python 2.3.5) if you installed the Developer Tools CD, but those are not suitable for running Zope. There is no danger in having more than one version of Python on a machine.

Most of this document is concerned with building Python correctly. As it turns out, if Python has the correct flags and options set during compilation then all modules and software that rely on it will compile a lot easier.

Python

After downloading and untarring the source package from www.python.org (use gnutar for unpacking instead of the built-in tar, and don't let StuffIt expander do it for you) you should "cd" into the top level directory of the python source tree. For Python versions 2.1.3 you configure like this:

  [statler:~] jens% ./configure --with-suffix=.exe --with-dyld

This will configure the sources to be built with support for the specific shared library architecture used in OS X and make sure that the binaries will be named "python.exe" and "python2.1.exe". This naming is important due to the case-insensitive nature of the HFS file system, otherwise the last step would fail where the binary is copied into the toplevel directory, which already contains an item named "Python".

For Python 2.2.x/2.3.x/2.4.x this step is much easier:

  [statler:~] jens% ./configure

If you are running OS X 10.4 and you are trying to compile Python 2.3.5 you will need to massage the generated pyconfig.h before you can build the software. Florent Guillaume explains what values need resetting on his blog.

With the environment set up correctly you can build the sources:

  [statler:~] jens% make

If you see messages during the build that complain about failed shared library building (something like "cc exited with status 1") make sure you retrace your previous steps to conform to these instructions. Before trying to compile again make sure you remove compiled stuff by executing:

 [statler:~] jens% make clean

If the compilation has finished you can test it using the unit tests that come with python. For Python 2.1.3 and 2.2.x you need to increase your shell's stack size. This change will only apply to the session you are currently running and will allow the "re " and "sre" module tests to finish successfully:

  [statler:~] jens% limit stack 4096

This assumes the stock tcsh shell, if you run bash you need to say:

  [statler:~] jens% ulimit 4096

Now you are ready to test your build. To run the unit tests simply execute

  [statler:~] jens% make test

The tests should run successfully. They are run several times, you can interrupt testing by simultaneously pressing <control> and c.

The last step is to install the binaries and libraries into their final resting place, which is under /usr/local/... by default:

  [statler:~] jens% make install

If this fails you are probably not running this as root. add "sudo" in front of "make install" and it should work. The binaries will have an ".exe" suffix and you can simply go to /usr/local/bin and rename them to your liking.

Since the paths are not immediately updated the easiest way to make sure your shell "sees" the new binaries is to close your current terminal session and open a new one.

Zope 2.4.x - 2.6.x

With Python compiled the way described above building Zope becomes child's play. Unpack your Zope source release (again, make sure you use gnutar and not tar), change into the toplevel Zope source directory and start the build script:

  [statler:~] jens% python2.1.exe wo_pcgi.py

This assumes that you did not rename the python binary, if you did you need to use the new name of course.

Zope 2.7-2.8

You can follow the build and install instruction in INSTALL.txt that you can find in the "doc" directory in the unpacked Zope 2.7 source package. The steps are very straightforward and apply to all Unices, including OS X.

Things to watch out for

Eric Francoeur reported that his OS X 10.1 Server setup had problems where during the Python "make test" step the test_socket test failed with "host not found" and he saw a traceback like this when starting Zope:

  2001-11-16T18:08:12 PANIC(300) z2 Startup exception Traceback (innermost last)
:
  File /Applications/Zope-2.4.3-src/z2.py, line 625, in ?
  File /Applications/Zope-2.4.3-src/ZServer/HTTPServer.py, line 396, in __init__
  File /Applications/Zope-2.4.3-src/ZServer/medusa/http_server.py, line 578, in __init__
  error: host not found

The reason for this failure is that the host name his machine had could not be res olved by his name server. You can test this by checking your machine's hostname and w hether it can be resolved or not by following these steps using Terminal.app (the out put from my own machine is shown):

  [statler:~] jens% hostname
  statler.dataflake.org
  [statler:~] jens% nslookup statler.dataflake.org
  Server:  bunsen.dataflake.org
  Address:  192.168.168.3

  Name:    statler.dataflake.org
  Address:  192.168.168.9

If you see an error message you can force OS X to set a new hostname for your mach ine by issuing the following command in Terminal.app:

  [statler:~] jens% hostname -s new.host.name

This command must be done with root privileges, so you either change to the root account or you prefix the command with "sudo".

In Mac OS X 10.3, if you go through the advanced setup option you will find a selection of gcc compiler versions to install. Do not try to build Python with gcc 2.95.2, it will not run correctly! Instead, rely on the later gcc version. If you have installed gcc 2.95.2, which apparently makes it the default gcc version to use, you can get yourself out of this bind by forcing the system to use gcc 3:

 [statler:~] jens% sudo gcc_select 3 

Thanks go to Jules Allen for pointing this out.

When building and installing Zope 2.7 you will at one point be asked to run the mkzopeinstance.py script to create the Instance home. D. Evan Kiefer ran into the following error message while running the script as instructed during installation:

 [statler:~] jens%  /opt/Zope-2.7/bin/mkzopeinstance.py
 Please choose a directory in which you'd like to install
 Zope "instance home" files such as database files, configuration
 files, etc.

 Directory: /var/zope_instance_home
 /usr/local/lib/python2.3/termios.py:7: DeprecationWarning: the TERMIOS module is deprecated; please use termios
   DeprecationWarning)
 Please choose a username and password for the initial user.
 These will be the credentials you use to initially manage
 your new Zope instance.

 Username: zopeadmin
 /usr/local/lib/python2.3/fcntl.py:7: DeprecationWarning: the FCNTL module is deprecated; please use fcntl
   DeprecationWarning)
 Traceback (most recent call last):
   File "/opt/Zope-2.7/bin/mkzopeinstance.py", line 174, in ?
     main()
   File "/opt/Zope-2.7/bin/mkzopeinstance.py", line 92, in main
     user, password = get_inituser()
   File "/opt/Zope-2.7/bin/mkzopeinstance.py", line 155, in get_inituser
     passwd = getpass.getpass("Password: ")
   File "/usr/local/lib/python2.3/plat-mac/EasyDialogs.py", line 150, in AskPassword
     _interact()
   File "/usr/local/lib/python2.3/plat-mac/EasyDialogs.py", line 53, in _interact
     AE.AEInteractWithUser(50000000)
 MacOS.Error: (-1713, 'no user interaction is allowed')
 [statler:~] jens% 

The problem here seems to be that OS X wants to display an authentication dialog but fails. The solution is to run the script under the pythonw binary that ships with OS X instead of the python binary you built earlier:

 [statler:~] jens% /usr/bin/pythonw /opt/Zope-2.7/bin/mkzopeinstance.py 

This python binary is able to interact normally with the OS X authentication mechanism and the script will complete normally after the authentication dialogs have been satisfied.