Install python package in its own virtualenv

This will be a practical example with flexget, but with any other package the drill is the same.

Reasons for why you may want to do this:

  • Flexget comes with a lot dependecies.
  • Some of this depending libraries are requiring a specific version. For instance SQLAlchemy==0.7.4 while the latest version is 0.7.5 (as for now).
  • Avoid conflicts between the flexget depending libraries and the ones that are already installed (or will be in future).

How to do it:

  1. Install virtualenv:

    ~$ sudo pip install virtualenv
    or
    ~$ sudo pip-3.2 install virtualenv

    If you want the default python version to be used inside virtualenv to be 3.2 (I choose that one because most of the code I wrote is in 3.2). Anyway flexget requires python2.x, so I’ll use the --python option later, check out the virtualenv help:
    ~$ virtualenv -h
    [...]
    -p PYTHON_EXE, --python=PYTHON_EXE
    The Python interpreter to use, e.g.,
    --python=python2.5 will use the python2.5 interpreter
    to create the new environment. The default is the
    interpreter that virtualenv was installed with
    (/usr/bin/python3)

  2. Choose where to place the virtual envairoment. /usr/local/lib will be a good choice:
    ~$ cd /usr/local/lib

  3. Creating the virtual envairoment.
    With options:
    --no-site-packages
    --distribute
    -p /usr/bin/python2.7

    /usr/local/lib$ sudo virtualenv flexget_virtual_env --no-site-packages --distribute -p /usr/bin/python2.7
    Running virtualenv with interpreter /usr/bin/python2.7
    The --no-site-packages flag is deprecated; it is now the default behavior.
    New python executable in flexget_virtual_env/bin/python2.7
    Also creating executable in flexget_virtual_env/bin/python
    Installing distribute...........................................................
    ................................................................................
    ..................................................done.
    Installing pip...............done.

  4. With the virtualenv-pip install flexget:
    /usr/local/lib$ cd flexget_virtual_env/bin
    /usr/local/lib/flexget_virtual_env/bin$ ls
    activate activate.fish easy_install pip python
    activate.csh activate_this.py easy_install-2.7 pip-2.7 python2.7
    /usr/local/lib/flexget_virtual_env/bin$ sudo ./pip install flexget
    Downloading/unpacking flexget
    Downloading FlexGet-1.0r2724.tar.gz (699Kb): 699Kb downloaded
    Running setup.py egg_info for package flexget

    [...]

    Successfully installed flexget FeedParser SQLAlchemy PyYAML BeautifulSoup html5lib PyRSS2Gen pynzb progressbar jinja2 flask cherrypy requests Werkzeug certifi chardet
    Cleaning up...

    Well, that looks good.

  5. Copying the flexget script into /usr/bin/:
    /usr/local/lib/flexget_virtual_env/bin$ sudo cp ./flexget /usr/bin/

  6. Let’s see if it works:
    /usr/local/lib/flexget_virtual_env/bin$ cd
    ~$ flexget --version
    1.0r2724

Done!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: