Showing posts with label virtualenv. Show all posts
Showing posts with label virtualenv. Show all posts

Feb 3, 2012

PIL with JPEG, ZLIB, FREETYPE2, LITTLECMS support in virtualenv on Ubuntu 11.10

To enable JPEG and PNG support install:
sudo apt-get install libjpeg8 libjpeg8-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install liblcms1 liblcms1-dev
On x64 system symlink libraries:
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/liblcms.so /usr/lib
cd /usr/include
ln -s freetype2 freetype
And finally in your virtualenv:
pip install PIL
You should see somethings like this during installation:
    PIL 1.1.7 SETUP SUMMARY
    --------------------------------------------------------------------
    version       1.1.7
    platform      linux2 2.6.7 (r267:88850, Aug 11 2011, 12:18:09)
                  [GCC 4.6.1]
    --------------------------------------------------------------------
    *** TKINTER support not available
    --- JPEG support available
    --- ZLIB (PNG/ZIP) support available
    --- FREETYPE2 support available
    --- LITTLECMS support available
    --------------------------------------------------------------------

To check, for example jpeg support, execute:
python -vvv -c "import _imaging" 2>&1 | grep jpeg
Should output:
#   clear[2] jpeg_encoder
#   clear[2] jpeg_decoder
#   clear[2] jpeglib_version

Oct 16, 2011

Virtualenv + pip

Install easy_install, pip, virtualen

sudo apt-get install python-setuptools python-virtualenv python-pip

Create virtual environment

$ virtualenv --no-site-packages env # from version 1.7 --no-site-packages default behavior
$ source env/bin/activate

(env)$ export PYTHONPATH=  # sometimes required
(env)$ pip install django
# ...
(env)$ pip freeze > requirements.txt
(env)$ deactivate

$ virtualenv --no-site-packages env2
$ source env2/bin/activate
(env2)$ pip install -r requirements.txt

Pip

# concrete package version
(env)$ pip install ipython==0.11

# archive link
(env)$ pip install -f http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz matplotlib

# install for concrete python interpreter version
sudo pip install ipython -E python2.5

Bonuses

List all packages with requirements:
pip list --local | awk '{print $1}' | xargs pip show | grep -v -e '^Location' -e '^Requires: $'
yolk - list installed packages
(env2)$ pip install yolk
(env2)$ yolk -l
vanity - list available versions
(env2)$ pip install vanity
(env2)$ vanity django -v

PyCharm

If you use PyCharm you’ll want to set up your virtualenv there for your project. Edit your project settings. Select Python Interpreter -> Add -> Specify Other… Add python from your virtual_env (env/bin/python)

Aug 19, 2011

Virtualenv in new Terminal windows/tabs

Just a simple trick to make Terminal open new tabs or windows with the last virtualenv you’ve activated. It does not actually do any wonders, but may be helpful for some. (You’ll need to have virtualenvwrapper installed for this to work.)

Run these commands in your console, they will edit necessary files:

echo 'basename "$VIRTUAL_ENV" > ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postactivate
echo 'rm ~/.last_venv' >> $VIRTUALENVWRAPPER_HOOK_DIR/postdeactivate

Then open your `~/.bashrc` or `~/.profile` or whatever your shell uses and append:

if [ -e ~/.last_venv ]; then
    workon `cat ~/.last_venv`
fi