FreeBSD ports and Python versions
September 2014
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
About
This site is an effort to share some of the base knowledge I have gathered through all this years working with Linux, FreeBSD, OpenBSD, Python or Zope, among others. So, take a look around and I hope you will find the contents useful.
Recent Entries
Recent Comments
Recent Trackbacks
Categories
OpenBSD (8 items)
BSD (0 items)
FreeBSD (19 items)
Linux (3 items)
Security (3 items)
Python (18 items)
Zope (13 items)
Daily (139 items)
e-shell (9 items)
Hacks (13 items)
PostgreSQL (3 items)
OSX (7 items)
Nintendo DS (0 items)
enlightenment (0 items)
Apache (3 items)
Nintendo Wii (1 items)
Django (23 items)
Music (12 items)
Plone (7 items)
Varnish (0 items)
Lugo (2 items)
Sendmail (0 items)
europython (7 items)
Cherokee (1 items)
self (1 items)
Nature (1 items)
Hiking (0 items)
uwsgi (0 items)
nginx (0 items)
bikes (0 items)
Archives

Syndicate this site (XML)

RSS/RDF 0.91

24 enero
2008

FreeBSD ports and Python versions

or how the env magic saved me again...

If you have some experience with FreeBSD ports, and more precisely with Python related ones (for example, extra modules like imaging or psycopg), you should already noticed that it is common to have two different python versions installed in the same system.

For example, in one of my FreeBSD servers, I've both Python 2.4 and 2.5 installed, because 2.5 is the current stable version, but I need 2.4 for certain things, like Zope.

And what happens when you need an additional module for a given version of Python ?

While working in that server today, trying to set up a Plone site. I noticed that I needed the python imaging module. I checked with pkg_info (because I thought it was already installed) and I found that there is already a version installed of such module:

[prunus] /var/log> pkg_info | grep imaging
py25-imaging-1.1.6_2 The Python Imaging Library
[prunus] /var/log>

The module was installed for Python 2.5. The problem was that Plone runs on top of Zope, which needs Python 2.4, and as I do not have the module for that version of Python installed, Plone didn't find it.

No problem, I just went to /usr/ports/graphics/py-imaging and perform another make install.

As you could imagine, it tried to re-install the py25-imaging package and, obviously, it crashes:

===>  Checking if graphics/py-imaging already installed
===>   py25-imaging-1.1.6_2 is already installed
      You may wish to ``make deinstall'' and install this port again
      by ``make reinstall'' to upgrade it properly.
      If you really wish to overwrite the old port of graphics/py-imaging
      without deleting it first, set the variable "FORCE_PKG_REGISTER"
      in your environment or the "make install" command line.
*** Error code 1

Ugly.

After reading carefully the error message, I opened the Makefile inside the port directory, just searching for some knobs or options to set the default Python version... but no luck. What now?

Well, after some googling I found something interesting in the porters handbook:

"The Ports Collection supports parallel installation of multiple Python versions. Ports should make sure to use a correct python interpreter, according to the user-settable PYTHON_VERSION variable."

AHA! it was PYTHON_VERSION... So the only thing I need is to set up such variable in the user environment to get the correct version of the module installed:

prunus# setenv PYTHON_VERSION python2.4
prunus# make clean install
===>  Cleaning for py24-imaging-1.1.6_2
===>  Found saved configuration for py25-imaging-1.1.6_2
===>  Extracting for py24-imaging-1.1.6_2
=> MD5 Checksum OK for python/Imaging-1.1.6.tar.gz.
=> SHA256 Checksum OK for python/Imaging-1.1.6.tar.gz.
===>  Patching for py24-imaging-1.1.6_2
===>  Applying FreeBSD patches for py24-imaging-1.1.6_2

[ ... ]

===>   Registering installation for py24-imaging-1.1.6_2
prunus#

NOTE: probably you already noticed it, this time, I wasn't using sudo, because if I've had added the PYTHON_VERSION variable to my user env and then used sudo, the process executed through sudo couldn't be able to access that environment variable.

UPDATE: As betabug said in the comments, you can pass environment variables to sudo, for example, to install elementtree for both python 2.5 and 2.4:

[prunus] /usr/ports/devel/py-elementtree> sudo make install
=> elementtree-1.2.6-20050316.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from http://effbot.org/downloads/.

[ ... ]

===>   Registering installation for py25-elementtree-1.2.6
[prunus] /usr/ports/devel/py-elementtree> sudo make clean
===>  Cleaning for py25-elementtree-1.2.6
[prunus] /usr/ports/devel/py-elementtree> sudo env PYTHON_VERSION=python2.4 make install
===>  Extracting for py24-elementtree-1.2.6
=> MD5 Checksum OK for elementtree-1.2.6-20050316.tar.gz.

[ ... ]

===>   Registering installation for py24-elementtree-1.2.6
[prunus] /usr/ports/devel/py-elementtree>

Posted by wu at 14:15 | Comments (0) | Trackbacks (0)
<< Django People | Main | OSx dns cache >>
Comments
Re: FreeBSD ports and Python versions

sudo env PYTHON_VERSION=python2.4 make clean install

Posted by: betabug at enero 25,2008 08:14
Re: FreeBSD ports and Python versions

Yes, due to the new sudo behaviour, environment variables must be set when calling sudo...

thnx betabug!

Posted by: Wu at enero 25,2008 09:14
Re: FreeBSD ports and Python versions

I just upgraded to Python 2.6 and was facing a similar problem. However, I wanted to make the setting more permanent, so I added "PYTHON_VERSION=python2.6" to /etc/make.conf.

Worked like charm. Thanks for the tips.

Posted by: Viktor Petersson at noviembre 13,2008 19:29
Re: FreeBSD ports and Python versions

Hi Viktor.

Yes, that's the way to make the PYTHON_VERSION env var available without having to set it up every time. The thing about that is that the default "stable" version is already the default one with the ports (that is, currently, 2.5).

What about 2.6? too much changes? (I didn't notice it is even in the ports tree :( )

Posted by: Wu at noviembre 15,2008 17:50
Trackbacks
Please send trackback to:http://blog.e-shell.org/35/tbping
There are no trackbacks.
Post a comment