Tag Archives: virtual environment

Installing nltk3 for Python3 in virtual environment on Linux

[Last update: 04/01/2015]

Prerequisites: Install Python and set up virtual environment  & Install pip in virtual environment
Tested on: Xubuntu 12.04 LTS / 13.10 / 14.04 LTS (64-bit) with ActivePython installed in /opt

  • (skip, if activated) Activate the virtual environment you would like to install nltk (v3) in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Use pip to install the latest version of nltk:
  1. (apy3341):~$ pip install -U nltk
  • [January 2015] Workaround for users with setuptools versions >=10 (see NLTK Issue #824):
  1. (apy3341):~$ pip install setuptools==9.1
    (apy3341):~$ pip install -U nltk
  • (skip, if nltk_data already present on system) Start Python interpreter in virtual environment and download nltk_data (corpora, packages & models):
(apy3341) mki@ubuntu:~$ python
ActivePython 3.3.4.1 (ActiveState Software Inc.) based on
Python 3.3.4 (default, Feb 25 2014, 14:59:15) 
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.download()

pip installations of sphinx, numpy & imapclient in virtual environment on Linux work out-of-the-box

Prerequisites: Install Python and set up virtual environment  & Install pip in virtual environment
Tested on: Xubuntu 12.04 LTS / 13.10 / 14.04 LTS (64-bit) with ActivePython installed in /opt

[Last update: 03/07/2014]

  • (skip, if activated) Activate the virtual environment you would like to install additional python packages in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Use pip to install/update additional packages (the installation of the following packages worked out-of-the-box):
  1. bin/pip install -U sphinx
    1. bin/pip install -U numpy
    1. bin/pip install -U imapclient

Installing lxml in virtual environment on Linux

Prerequisites: Install Python and set up virtual environment  & Install pip in virtual environment
Tested on: Xubuntu 12.04 LTS / 13.10 / 14.04 LTS (64-bit) with ActivePython installed in /opt

[Last update: 03/07/2014]

  • (skip, if activated) Activate the virtual environment you would like to install lxml in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Install/check for lxml dependencies (for pip to be able to compile lxml from source code):
  1. sudo apt-get install libxml2-dev libxslt1-dev zlib1g zlib1g-dev
  • Use pip to install/update lxml:
  1. bin/pip install -U lxml

Installing ipython in virtual environment on Linux

Prerequisites: Install Python and set up virtual environment  & Install pip in virtual environment
Tested on: Xubuntu 12.04 LTS / 13.10 / 14.04 LTS (64-bit) with ActivePython installed in /opt

[Last update: 03/07/2014]

  • (skip, if activated) Activate the virtual environment you would like to install ipython in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Make sure that readline support is installed in your virtual environment (prerequisite for ipython’s colour prompts).
  • Use pip to install/update readline:
  1. bin/pip install -U ipython

Installing readline support in ActivePython virtual environment on Linux

Prerequisites: Install Python and set up virtual environment  & Install pip in virtual environment
Tested on: Xubuntu 12.04 LTS / 13.10 / 14.04 LTS (64-bit) with ActivePython installed in /opt

[Last update: 03/07/2014]

  • (skip, if activated) Activate the virtual environment you would like to install readline in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Install/check for readline dependencies (for pip to be able to compile readline from source code):
  1. sudo apt-get install libncurses5-dev
  • Use pip to install/update readline:
  1. bin/pip install -U readline

Installing pip in virtual environment

[Last update: 03/07/2014]

Prerequisites: Install Python and set up virtual environment
Tested on: Xubuntu 12.04 LTS / 14.04 LTS (64-bit) with ActivePython installed in /opt

  • (skip, if activated) Activate the virtual environment you would like to install pip in:
  1. cd ~/venv/apy3341
    source bin/activate
  • Download “get-pip.py“:
  1. curl https://bootstrap.pypa.io/get-pip.py > bin/get-pip.py
  • Download and install pip (the latest version of setuptools will be installed automatically):
  1.  bin/python bin/get-pip.py

Setting up Python developing environment on Xubuntu 12.04 LTS / 14.04 LTS

Installing ActivePython

[Last update: 03/07/2014]

My favourite cross-platform binary distribution is ActivePython. Check download area for latest release and adapt version number and platform accordingly.

[Note: If you mainly use Unix-based systems, setting up different Python versions and virtual environments using pyenv might be even more convenient than ActivePython.]

On Ubuntu/Xubuntu 64-bit (12.04 LTS / 14.04 LTS), I use the following commands and install ActivePython in the location /opt/ActivePython-X.X.X.X:

cd /tmp
wget http://downloads.activestate.com/ActivePython/releases/3.3.4.1/ActivePython-3.3.4.1-linux-x86_64.tar.gz
tar -xvf ActivePython-3.3.4.1-linux-x86_64.tar.gz
cd ActivePython-3.3.4.1-linux-x86_64
sudo ./install.sh

Setting up virtual environment

Use ActivePython’s pre-configured pyvenv.py script to generate a virtual environment.

cd /opt/ActivePython-3.3.4.1/bin/
./pyvenv ~/venv/apy3341

Activating virtual environment

cd ~/venv/apy3341
source bin/activate

The name of the activated virtual environment is shown in brackets at the beginning of the commandline prompt:

(apy3341) mki@ubuntu:~$

Using python in the virual environment

(apy3341) mki@ubuntu:~$ python
ActivePython 3.3.4.1 (ActiveState Software Inc.) based on
Python 3.3.4 (default, Sep 16 2013, 23:12:56) 
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Deactivating virtual environment

(apy3341) mki@ubuntu:~$ deactivate

commandline prompt returns back to normal and system-wide python binaries are used (here Xubuntu 12.04 LTS):

mki@ubuntu:~$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>