Use a different Python version as default

kamikaze

Well-Known Member

Reaction score: 75
Messages: 365

This little howto explains how to set another Python version as the default and update all python packages to follow the transition.

As an example we will use Python 2.6 as the new default. Python 3.0 would probably not work, because it's incompatible with many of the Python 2.x software packages.

First add the following lines to your /etc/make.conf:
Code:
PYTHON_VERSION=		2.6
PYTHON_DEFAULT_VERSION=	2.6
Then you have to update the base python port (either with portmaster, portupgrade or a similar tool). Using [cmd=pkg_delete]-f[/cmd] and [cmd=make]install[/cmd] directly would break the dependencies.

One of the following commands should do the trick under the assumption that 2.5 is the current default:
  • # portmaster -o lang/python26 lang/python25
  • # portupgrade -o lang/python26 lang/python25

Now all these little python libraries need to be rebuild. The following commands are also under the assumption that 2.5 is the current default.
  • # pkg_info -qox py25-\* | xargs -o portmaster
  • # pkg_info -qox py25-\* | xargs -o portupgrade -f

Now, you're almost done, your system has been upgraded to Python 2.6. However there still might be Python software left that does not have the practical py-prefix, the following command will help you find it:

  • # find /usr/local/lib/python2.5 -type f -exec pkg_info -W \{} \; | grep -Eo '[^ ]+$' | sort -u

It's probably a good idea to pipe the list into a file:

  • # find /usr/local/lib/python2.5 -type f -exec pkg_info -W \{} \; | grep -Eo '[^ ]+$' | sort -u > ~/pyrebuild

And now all that is left to do is rebuild them:
  • # xargs < ~/pyrebuild -o portmaster
  • # xargs < ~/pyrebuild -o portupgrade -f

After all packages have successfully been rebuild you can clean up the empty directories left behind:

  • # find -d /usr/local/lib/python2.5 -type d -exec rmdir \{} \;

This will only remove really empty directories.

The port x11/xcb-proto complained about being updated to 2.6, this could be mended by changing the Makefile:
Code:
-USE_PYTHON=	2.5
+USE_PYTHON=	2.5+
The port built and installed just fine with Python 2.6 on my 7.1-stable/amd64 box.
 

Android1

New Member


Messages: 14

At this point in time, are there any ports that are known to break when using Python 2.6 as opposed to 2.5?
 

athos

Member

Reaction score: 3
Messages: 44

Great information, very handy today, since many libraries require python2.7.
 
Top