Python Virtrualenvs on Archlinux

I'm working on the Kaggle datascience bowl, and thought it was a good time to get to grips with some of the python data processing and machine learning modules. Of course, I like keeping my system clean and dont want to haphazardly install all the modules willy-nilly. So virtual envs and virtualenvwrapper are convenient tools. These are my notes on setting it up on arch.

First we're going to isntall pip and virtual env, we dont need pip as venvs install pip into the venv when created, but worth getting it for shell completion.

bash sudo pacman -S python3-pip sudo pacman -S python3-virtualenv

Make pip play nice with zsh.

bash pip completion --zsh >> ~/.zprofile

venvwrapper is a nubmer of shell scripts that simplify working with and tracking venvs. I regret it fixes the virtual env base path, which affects how I organize projects. Although venvs can be linked to project directory using mkproject, which satisfies my organizational desires.

bash sudo pacman -S python-virtualenvwrapper # can create python2 venvs echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.zprofile export WORKON_HOME=~/venvs export PROJECT_HOME=~/projects mkdir -p $WORKON_HOME echo "export WORKON_HOME=$WORKON_HOME" >> ~/.zprofile echo "export PROJECT_HOME=$PROJECT_HOME" >> ~/.zprofile

Create a new venv and associated project. the -p option lets one specify the path to python, in this case i want to use python 2.7.

bash # print list of virtualenvwrapper commands and descriptions virtualenvwrapper mkproject -p /usr/bin/python2.7 2014-12-24_testdatascibowl

Check out the contents of $WORKON_HOME; some scripts in there, such as postmkvirtualenv let you run scripts automatically when doing venv operations. Convenient if you often use certain modules. I'll look into those more later.

``` bash # check out your venvs ls $WORKON_HOME

# check out packages in the active venv
lssitepackages

```

deactivate deactivates the current venv. One can also navigate to the active venv directory with cdvirtualenv.

Go Top
comments powered by Disqus