Tuesday, 17 January 2012

Solaris 9 [SunOS 5.9] - Installing Python from Source with SSL [This example uses 2.7.2]

This is a simple guide on how to install python on a Solaris 9 system. There are a few gotcha's which I am sharing and writing for future use.

1. Download Python. I took the compressed source tarball (.tgz). You are essentially compiling the source on your system.

2. Optional: Transferring it to the server. I had to transfer it to the server to install, so if you need to do that, see my previous post

3. Unzip the package using the following command. It will unzip, then untar.
Code Snippet
  1. gunzip -c PYTHONFILENAME.tgz |tar xvf -
End of Code Snippet

4. You now need to configure the source. This will produce a Makefile based on your system. Navigate to the Python source directory, and execute the following command...
Code Snippet
  1. ./configure --prefix=/usr/local
End of Code Snippet

5. Now we need to compile our Makefile that has been created.
Code Snippet
  1. make
End of Code Snippet

6. Ensure you are a root user before this step ("su root" - to change). Execute the following command to install Python.
Code Snippet
  1. make -i install
End of Code Snippet

7. If everything went well (it probably didn't - see below!). Add Python to your system PATH variable. This way, you don't need to refer to /usr/local everytime you execute a script. See my previous blog post on how to do this.

8. Simply execute the following command to check Python has set itself up correctly... Do this outside of the source directory, so you can test the PATH variable aswell.
Code Snippet
  1. python --version
End of Code Snippet

9. Get an ice cold beerski in!


During the make procedure, you receive the following...

./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl
/usr/bin/env: No such file or directory
make: *** [Python/Python-ast.c] Error 127

Simply touch the libraries it requires (see below), and re-try... (Run make clean before re-try)
Code Snippet
  1. touch Include/Python-ast.h Python/Python-ast.c
End of Code Snippet

During the install procedure, you receive the following...

make: ar: Command not found

You need to add ar to your PATH variable. This is located in /usr/ccs/bin. See my previous blog post on how to do this.

Note: If you are receiving an error while re-trying or you wish to remove temporary install files, simply execute the following command... "make clean"

Optional: Adding SSL Support to Python
Python needs to be compiled with SSL support... You can enable this by firstly installing the OpenSSL development libraries (libssl-dev download here) before the initial Python installation. Ensure you can open the OpenSSL console by typing openssl... If not, add it to your PATH. You then uncomment a few lines from the Modules/Setup.dist file.

Open the 'Modules/Setup.dist' file for editing, and uncomment the following lines (Assuming you installed OpenSSL to the default location)...

Code Snippet
  1. 204: # Socket module helper for SSL support; you must comment out the other
  2. 205: # socket line above, and possibly edit the SSL variable:
  3. 206: SSL=/usr/local/ssl
  4. 207: _ssl _ssl.c \
  5. 208:     -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
  6. 209:     -L$(SSL)/lib -lssl -lcrypto</pre>
End of Code Snippet

Save and close the file... then copy the file to /Setup. Otherwise Python will warn you this this file is newer than the Setup copy. You can now proceed to install Python with the instructions as above.

You can verify the installation by running the following test script...

Code Snippet
  1. python /usr/local/lib/python2.5/test/test_socket_ssl.py
End of Code Snippet

Module Errors
If you experience any errors with modules... then execute python's setup.py file. This will install all of the modules by default.

Code Snippet
  1. python setup.py install
End of Code Snippet

No comments: