Home Blog Install python package in its own virtualenv
Post
Cancel

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:

    1
    
     ~$ sudo pip install virtualenv
    

    or

    1
    
     ~$ 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:

    1
    2
    3
    4
    5
    6
    7
    8
    
     ~$ 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:
    1
    
     ~$ cd /usr/local/lib
    
  3. Creating the virtual enviroment. With options: --no-site-packages --distribute -p /usr/bin/python2.7

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
     /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:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
     /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/:

    1
    
     /usr/local/lib/flexget_virtual_env/bin$ sudo cp ./flexget /usr/bin/
    
  6. Let’s see if it works:

    1
    2
    3
    
     /usr/local/lib/flexget_virtual_env/bin$ cd
     ~$ flexget --version
     1.0r2724
    

Done!

This post is licensed under CC BY 4.0 by the author.

How to handle integer and string from input

Angry Birds are going into space

Comments powered by Disqus.