Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

Thursday, November 17, 2011

How to install cx_Oracle and oracle client on debian

In this post i'm going to explain how to install and use the python lib named cx_Oracle on a debian box. To make things a little more spicy, i will start from the assumption that oracle is not installed on the box, and that i don't want to install a full fledged oracle server on my box.

So after this procedure i will have a minimal install of oracle libs, that means the bare minimum to use cx_Oracle. More precisely, that means no oracle client, no sqlplus will be on that box.

The first step is to download the oracle instant client and the cx_Oracle library that matches. Out of laziness, i decided to use the pre compiled version of cx_Oracle.

Do download oracle instant client, go on oracle website here. Then choose the platform that / library that matches your oracle server. For me it was "instantclient-basiclite-linux32-11.2.0.2.0.zip"

Once you have downloaded that file unzip it and install it. I personnaly chose to install it in (i.e move the unzipped folder) into /usr/local/lib.

Once this done, you need to define two variables:
export ORACLE_HOME=/usr/local/lib/instantclient_11_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/instantclient_11_1

Once this is done, we can move on to install cx_Oracle. I downloaded the RPM version that matches my python and oracle version, in my case cx_Oracle-5.1.1-11g-py26-1.i386.rpm.

Being under debian, RPM is not the favored method to install packages. Fortunately there's an utility that allows to convert RPMs to DEB files called alien. Here's the steps to install alien and cx_Oracle:
# install alien
sudo apt-get install alien

# convert cx_Oracle-5.1.1-11g-py26-1.i386.rpm to cx_Oracle-5.1.1-11g-py26-1.i386.deb and install it
alien -i cx_Oracle-5.1.1-11g-py26-1.i386.rpm



Once that done, there's one last step. This installed cx_Oracle library was installed under /usr/lib/python2.6/site-packages. Unfortunatly by default, site-packages wasn't part of the default python search path. There's several ways to go around that which i won't describe at length (more details here under "Modifying Python’s Search Path"). I chose to modify site.py under /usr/lib/python2.6/ (mostly because it's the first but probably not the last package that will be installed in site-packages).

In order to do that I simply edited site.py and searched for addsitepackages and edited it as follow:
def addsitepackages(known_paths):
    """Add site-packages (and possibly site-python) to sys.path"""
    sitedirs = []
    seen = []

    for prefix in PREFIXES:
        if not prefix or prefix in seen:
            continue
        seen.append(prefix)

        if sys.platform in ('os2emx', 'riscos'):
            sitedirs.append(os.path.join(prefix, "Lib", "site-packages"))
        elif os.sep == '/':
            sitedirs.append(os.path.join(prefix, "local/lib",
                                        "python" + sys.version[:3],
                                        "dist-packages"))
            sitedirs.append(os.path.join(prefix, "lib",
                                        "python" + sys.version[:3],
                                        "dist-packages"))
            sitedirs.append(os.path.join(prefix, "lib", "dist-python"))

            ##################
        # added following line to make site-packages part of default search path
            #################
            sitedirs.append(os.path.join(prefix, "lib",
                                        "python" + sys.version[:3],
                                        "site-packages"))

        else:
            sitedirs.append(prefix)
            sitedirs.append(os.path.join(prefix, "lib", "site-packages"))

        if sys.platform == "darwin":
            # for framework builds *only* we add the standard Apple
            # locations. Currently only per-user, but /Library and
            # /Network/Library could be added too
            if 'Python.framework' in prefix:
                sitedirs.append(
                    os.path.expanduser(
                        os.path.join("~", "Library", "Python",
                                     sys.version[:3], "site-packages")))

    for sitedir in sitedirs:
        if os.path.isdir(sitedir):
            addsitedir(sitedir, known_paths)

    return known_paths

After all that, you should be able to type "import cx_Oracle".

Friday, October 14, 2011

Enabling proxy under Debian



In order to enabled a proxy, there's two main places (at least for my use this did the trick, there's probably are others). The first one is simple defining the following variables:
export http_proxy="http://your.proxy.com:your_port"
export ftp_proxy="http://your.proxy.com:your_port"

Secondly in order to have apt-get work through proxy, you need to update /etc/apt/apt.conf.d/proxy (or create it):
Acquire::http::Proxy "http:///your.proxy.com:your_port";



Monday, April 18, 2011

How to extract a DEB file

DEB files are ar archives, which contain three files:
  • debian-binary
  • control.tar.gz
  • data.tar.gz
The actual data is contained into data.tar.gz. You can extract it with the following command:
ar p yourfile.deb data.tar.gz | tar xz

Sunday, April 17, 2011

Compiling a linux kernel on a Debian "like" distribution

I recently had to re-compile a kernel, and there's a few preliminaries. You need to install a bunch of packages :

sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
sudo apt-get install kernel-package

After that you can follow the excellent guide here:

One point which I had missed though is where are the packages once you've finished compiling (although it's written in the guide). So if like they recommend in the you've extracted the kernel source under ~/src/linux-source-2.6.35 for instance, then the deb packages will be in ~/src.


Enjoy.

Tuesday, April 5, 2011

Find closest and fastest repository for your Debian

I recently installed a new distrib with linux mint based on Debian. I've done that scores of times, but one thing i never remember is how to find the best repo (and the fastest of course) based on your location.

There's a very neet package that will do the work for your:
sudo apt-get install netselect-apt
sudo netselect-apt

And Voila, you're done.


Monday, April 4, 2011

Update Debian Squeeze to Mint ~ a.k.a Mintify your Debian

I've been willing to install a new linux for a while, more precisely a Linux Mint distrib for various reasons. Call me lazy i didn't wanted to download and burn a full DVD. So the came the idea to use a Debian install as a base (since there is a version called LMDE base on Debian instead of Ubuntu.

At the time of this post, Debian has recently updated Squeeze to stable, so that the freshly baked Linux Mint isn't too far away (LMDE is supposed to be based on the current testing debian).

If you want to follow the same steps as me, this post assumes a couple of things:

  1. You can and will use command line without fear
  2. You know what debian is and can read log messages or use test installer
  3. You computer is already connected to internet


Some thanks to those two posts which i used as a base and mix together with my own twist:
HOWTO: Create a custom, minimal LMDE install
Mintifying Debian

Enough talk, let's get down to it. First you'll need to download a ISO of Debian, i used the businesscard version. You can find other version fitting to your need / architecture here:
http://www.debian.org/releases/squeeze/debian-installer/

1) Download it, burn it or put it on a USB key, which ever you prefer and install debian.

Once the install is completed, and you've added yourself as a sudoer ,you can proceed.



2) Then you may want to add the contrib and non-free Debian repositories by editing the file /etc/apt/sources.list and adding “contrib non-free” without quotes right at the end of each line ending with “main”.

4) Next you add the Debian Multimedia and the Mint repositories. You can for instance create a file within /etc/apt/sources.list.d called “lmde.list” and add these two lines into it:

deb http://packages.linuxmint.com/ debian main upstream import
deb http://www.debian-multimedia.org squeeze main non-free



5) Updates :

sudo apt-get update
sudo apt-get install linuxmint-keyring
wget -c http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2010.12.26_all.deb
sudo dpkg -i debian-multimedia-keyring_2010.12.26_all.deb
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade



Now the trick start here. Apparently when Squeeze went from testing to stable a particular package called "gstreamer0.10-pitfdll" has been removed from Debian repo cause the all meta package mint-meta-debian to fall to pieces. With some error message that look like:



The following packages have unmet dependencies:
mint-meta-debian : Depends: mint-meta-codecs but it is not going to be installed



The following packages have unmet dependencies:
mint-meta-codecs : Depends: gstreamer0.10-pitfdll but it is not installable
E: Broken packages





But fear not, here's the solution:
wget -c http://debian.securedservers.com/debian/pool/contrib/g/gstreamer0.10-pitfdll/gstreamer0.10-pitfdll_0.9.1.1+cvs20080215-1_i386.deb
dpkg -i gstreamer0.10-pitfdll_0.9.1.1+cvs20080215-1_i386.deb


Now you can safely proceeed to the Mintifying of your debian:
apt-get install mint-meta-debian

Enjoy.