[HOWTO] Install M2Crypto for Python 2.7 on Windows

I am using Windows 7 Home Premium 64-bit and had to setup M2Crypto required for a Python program that I am writing in Python 2.7 (32-bit). After hours of trying and searching, I finally managed to get it installed and working.

Here are some of the things that I tried, please move on to “How I managed to get it to work” if you don’t want to go through boring “What I tried” stuff.

What I tried:
First of all, I tried to install M2Crypto via pip. I got an error saying that swig.exe was not found, so I downloaded copy of swigwin and extracted it, then added the directory to system PATH. I installed easy_install (setuptools), opened the terminal and changed dir to Python27\Scripts and installed pip (easy_install pip). Then, I tried to install M2Crypto using pip:

pip install M2Crypto

Unfortunately, I got the following error:

SWIG\_m2crypto.i(31) : Error: Unable to find ‘openssl\opensslv.h’

SWIG\_m2crypto.i(45) : Error: Unable to find ‘openssl\safestack.h’

SWIG\_evp.i(12) : Error: Unable to find ‘openssl\opensslconf.h’

SWIG\_ec.i(7) : Error: Unable to find ‘openssl\opensslconf.h’

error: command ‘swig.exe’ failed with exit status 1

So, I downloaded openssl source files and copied the include directory to swig_dir/lib, then I got errors that from swig. I also tried giving build_dist parameter to setup.py but in vain. I was thinking of compiling openssl myself, but I figured that I would require Visual Studio (which I do not have). I thought of using MingW, but turns out you need to compile Python with MingW for it to work. I almost gave up on this, but I found that some developers had contributed build of OpenSSL and M2Crypto, so that I could just install them. Move on to next section to do it yourself.

How I managed to get it to work
I downloaded pre-built binaries of M2Crypto built against OpenSSL 1.0 from M2Crypto Wiki. The one that I downloaded is M2Crypto-0.21.1.win32-py2.7.msi. Then, I set it up. It detected my Python installation and installed the package. However, when I ran the Python script, I got the following error:

import __m2crypto
ImportError: DLL load failed

I don’t know if it was because I did not restart my computer after installation or if OpenSSL dlls were missing, in either case, you may want to install Win32 OpenSSL V1 Light and install it and it should work.

Hope this helps.

[HOWTO] Install easy_install and pip in Python 3 (Windows)

I am just starting with Python 3 on Windows and I wanted to install easy_install and/or pip for installing other available packages easily. However, I found that setuptools setup for Python 3.3.2 (the version I am using) is not available.

I discovered distribute, a fork of setuptools, which provides easy_install. I downloaded source from Python Package page for distribute and extracted it. In the elevated command prompt (cmd->Run as Administrator), I changed to extracted directory and then ran distribute_setup.py. Then, easy_install was successfully installed in Python_Directory\Scripts. Then, I could install pip by changing directory to Scripts and running the following:

easy_install pip

Hope this helps.

[SOLVED] “Warning: Could not find package list for PPA: ppa:some/ppa” while trying to use ppa-purge in Ubuntu

When trying to purge Gnome3 PPA, I had to cancel the ppa-purge process and when I tried to run the same, I got the following message:

Updating packages lists
PPA to be removed: gnome3-team gnome3
Warning: Could not find package list for PPA: gnome3-team gnome3

I had to add the PPA again to be able to successfully run ppa-purge. For example, if your ppa is ppa:gnome3-team/gnome3, you should run the following:

apt-add-repository ppa:gnome3-team/gnome3

Then you should be able to run ppa-purge again.

Note: In my case, I also got the following error after adding the PPA again:

E: Type ‘ain’ is not known on line 3 in source list /etc/apt/sources.list.d/gnome3-team-gnome3-natty.list
E: The list of sources could not be read.
Warning: apt-get update failed for some reason
PPA to be removed: gnome3-team gnome3
Warning: Could not find package list for PPA: gnome3-team gnome3

This seems to be some bug. I had to manually edit /etc/apt/sources.list.d/gnome3-team-gnome3-natty.list and remove the line containing ‘ain’. This should not be required in your case.

If this does not work, you should check if the PPA exists at all and if you have packages installed from that PPA.

[SOLVED] Netbeans svn error “Duplicate extensions not allowed, OPTIONS request failed on ‘path'”

I have installed sun-java-jre/jdk on my Ubuntu and Fedora. I am using svn for my project and have been running it well with my old Fedora 15 installation on my old PC. However, recently I installed Fedora on my other machine and installed Netbeans 7.0.1 on top of sun-java. Fedora did not handle graphics very well, so I installed Ubuntu alongside as well. But every time I tried to access subversion functionality from Netbeans, I got the following error:

org.tigris.subversion.javahl.ClientException: java.io.IOException: Duplicate extensions not allowed
OPTIONS request failed on ‘/relative/path/to/some/project/directory’

This happened in both of my newer installations, Fedora 15 and Ubuntu 11.04, both with Netbeans 7.0.1. I tried several things but all in vain. Finally, when searching for installed Java related packages in my old machine (where subversion always worked), I found the required package. The cryptic error message will simply stop appearing and Netbeans subversion will start working after the installation of svn client adapter for Netbeans. Here is how you can do it from the terminal:

For Fedora:

su -c 'yum install netbeans-svnclientadapter'

For Ubuntu:

sudo apt-get install libnb-svnclientadapter-java

Hope this helps.

[SOLVED] Blank dark screen after installing ATI Proprietary Drivers (fglrx) in Ubuntu 11.04 Natty Narwhal

Having video and sound issues with Fedora 15, I decided to try out Natty on my HP Pavilion G4 1009tx. Surprisingly, sound and 3D effects ran great with Intel onboard graphics so I installed it onto the Hard drive. In all excitement, I decided to try out proprietary ATI drivers for the switchable dedicated AMD Radeon HD 6470M graphics. However, when I rebooted, it would not boot. It seems that plymouth crashes and system ends up with a black screen. So, I decided to remove fglrx and keep on using Intel card but it seems that I can’t even boot into recovery mode. So, I had to remove fglrx and make the system usable again using the Live CD and chroot. Here is how I did it.

Note: If you are trying to get the fglrx to work, you should look somewhere else. I just removed fglrx and decided not to use it (for now at least).

First, I booted into the Live Ubuntu Desktop. Then, I opened the terminal and created a directory for mounting everything:

sudo mkdir /mnt/root

Then I mounted the root partition.

sudo mount /dev/sda7 /mnt/root

Please note that my installation’s root partition is /dev/sda7. In your case, it can be something else. Since I have a separate home partition (/dev/sda8), I mounted it too, just in case. You can skip this if you don’t have a dedicated home partition.

sudo mount /dev/sda8 /mnt/root/home

You should also mount other drives if you have dedicated partitions for other directories (for /boot perhaps?).

Then, I mounted other required directories.

sudo mount -o bind /dev /mnt/root/dev
sudo mount -o bind /proc /mnt/root/proc
sudo mount -o bind /sys /mnt/root/sys

Then, I chrooted to the mounted root:

sudo chroot /mnt/root

Now, I got into the root of my installed Ubuntu. Then I just had to run the following to remove fglrx:

apt-get remove fglrx

(ignore this, see UPDATE 2 below)
After upgrading xserver-xorg-video-all, xserver-xorg-video-ati and xserver-xorg-video-radeon, the screen went blank again after reboot. So, I had to downgrade the packages by downloading from repos. Here is how you can do it too (I have included the packages in an archive, please note that you need an active Internet connection for the following):

cd /tmp
wget http://www.khattam.info/wp-content/uploads/xserver-ati-old.tar.gz
tar xzvf xserver-ati-old.tar.gz
dpkg -i xserver-xorg-video-radeon_6.14.0-0ubuntu4_i386.deb xserver-xorg-video-ati_6.14.0-0ubuntu4_i386.deb xserver-xorg-video-all_1%3a7.6+4ubuntu3_i386.deb

This blank screen issue would still reappear once in a while and the laptop would get very hot over prolonged usage, so I decided to go for a slightly different solution. I removedxserver-xorg-video-radeon and xserver-xorg-video-ati, blacklisted the radeon module and disabled it via vgaswitcheroo. Here is how I did it:
Remove ATI Radeon drivers:

apt-get remove xserver-xorg-video-ati xserver-xorg-video-radeon

Blacklist kernel module:
To disable kernel module, I opened the file /etc/modeprobe.d/blacklist.conf and add a line ‘blacklist radeon’. You can use nano to do this:

nano /etc/modprobe.d/blacklist.conf

Ctrl+O to save and Ctrl+X to exit nano.
Re-enable kernel module after startup and switch the card off:
To do this, I just added two lines before the line ‘exit 0’ in /etc/rc.local (you can use nano for this too) so that the file looks like the following:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

modprobe radeon
chown USERNAME /sys/kernel/debug/vgaswitcheroo/switch
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

exit 0

In the file above, USERNAME is my login username. Don’t forget to replace USERNAME with your username before saving the file. (If you are not sure what your username is, just do this: ls /home/, you should see it in the name of the directory.)

When done, I just exited from the chrooted environment:


Then, I unmounted everything:

sudo umount -a

(You’ll see some error messages, like device is busy, just ignore them)

Now, I am able to boot into the installed Ubuntu again. Hope this helps.