Fixing broken Python on Gentoo with Paludis
Have you ever run a script that should do some things you wanted it to do, but instead you ended up with your system partially messed up? Unfortunately, such things do happen.
I have no idea how simple setup.py
script could destroy Python libraries, but Gentoo with messed up Python (and furthermore, with unusable Portage) didn’t seem to be useful. So I had to find a solution.
The first attempt
It would be great, if I could just simply re-emerge dev-lang/python-2.6.*
, but as I already said, portage was broken.
I tried to reinstall Python manually, but with no luck. Python 2.5, other portage versions, etc. - still no luck.
I decided not to use a LiveCD, because fixing it without reboot seemed to be a nice challenge.
So I came up with…
The final solution
“Remember that faster-than-speed-of-portage thing called Paludis, which seems to be a nice alternative to Portage?”
“Yup.”
“It’s written in C++, isn’t it?”
“Yup.”
And all I had to do was:
- install Paludis manually
- install Python via Paludis
- reinstall Paludis via Portage or remove it completely
Manual Paludis installation
Download and install
First of all, we need a Paludis source tarball, so simply run:
wget http://linux.rz.ruhr-uni-bochum.de/download/gentoo-mirror/distfiles/paludis-0.44.1.tar.bz2
or use any other server or version. Then:
tar xf paludis-0.44.1.tar.bz2
cd paludis-0.44.1
We’ll install Paludis system-wide, in order to avoid some configuration problems I have encountered and didn’t want to fight with:
./configure
make
make install
I also needed to run
ldconfig
due to “paludis: error while loading shared libraries (…)” error.
Configure
Paludis will look for the default configuration files in /etc/paludis
or /root/.paludis
, so you may choose any of them. I’ve chosen the latter.
Now we have to create some directories and some configuration files. If you want to know more about configuring Paludis manually look at the official guide.
mkdir -p /root/.paludis/repositories
Then create /root/.paludis/environment.conf and let it contain at least this one line, specifying the world file location:
world = /var/db/pkg/world
While operating with reduced privileges, Paludis will try to use the paludisbuild username, or the one specified in environment.conf. So if you want to change that, add the line:
reduced_username = anyuser
Then create that user if it’s necessary, e.g.:
useradd -r paludisbuild
and remember to add permissions to access some of the directories used by Paludis.
There are still some configuration files left. Change corresponding lines if you’re not using amd64 and the default/linux/amd64/10.0/desktop profile.
/root/.paludis/keywords.conf to set the amd64 (or other) as a default keyword:
*/* amd64
/root/.paludis/licenses.conf to accept all licenses:
*/* *
/root/.paludis/bashrc if you want to set CLAGS, etc.:
CFLAGS="-march=core2 -O2 -pipe -msse4.1"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j3"
Then we’ll create configuration files for two repositories (adjust the profiles line):
/root/.paludis/repositories/gentoo.conf:
location = /usr/portage
sync = rsync://rsync.europe.gentoo.org/gentoo-portage/
profiles = ${location}/profiles/default/linux/amd64/10.0/desktop
format = ebuild
names_cache = /var/empty
and /root/.paludis/repositories/installed.conf:
location = /var/db/pkg/
format = vdb
names_cache = /var/empty
provides_cache = /var/empty
Setting all caches to /var/empty
means that we don’t want to use them. All in all, it’s going to be a temporary installation.
I also had to create directories: /var/tmp/paludis
and /var/log/paludis
.
You may need to change permissions, so that all these directories are accessible by Paludis.
Try to run:
paludis --info
to ensure that everything seems OK.
Using Paludis
Assuming that everything worked as expected, the hardest part is behind us. Now we may at last install Python:
paludis --sync
paludis --install =dev-lang/python-2.6*
And assuming that this also worked as expected, we now have freshly reinstalled Python 2.6 and all that’s left is to clean up the mess we’ve done. You may now emerge Paludis and keep it in case of emergency, or remove all the Paludis stuff.