Skip to content

Instantly share code, notes, and snippets.

@stormwild
Last active August 21, 2017 16:02
Show Gist options
  • Save stormwild/0e3bd0c238d581bdee2283146f4d049a to your computer and use it in GitHub Desktop.
Save stormwild/0e3bd0c238d581bdee2283146f4d049a to your computer and use it in GitHub Desktop.
Setup python dev environment on Ubuntu 14
sudo apt-get install build-essential python-dev libsqlite3-dev libreadline6-dev libgdbm-dev zlib1g-dev libbz2-dev sqlite3 zip
sudo apt-get install python3 python3-dev

Install python3

$ sudo apt-get install python3 python3-dev

Enable easy_install

To use easy_install you need to install setuptools. setuptools is not maintained so then instead of it, distribute take the place of it. but now setup tool is updated. if you want to know more check official site

$ mkdir ~/src

Download setup file.

$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

Execute it and start install

$ sudo python ez_setup.py

Install pip

After enabling easy_install, install pip next. What is pip? check document

$ sudo easy_install pip

Install virtualenv and virtualenvwrapper

Virtualenv enables you to make different environment with version python or combination of package. virtualenv

$ sudo pip install virtualenv virtualenvwrapper

Setting for virtualenvrapper

$ vim ~/.bashrc
~/.bashrc

if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
    export WORKON_HOME=$HOME/.virtualenvs
    source /usr/local/bin/virtualenvwrapper.sh
fi
$ source ~/.bashrc

Now you can make virtual python environment easily.

mkvirtualenv : make virtualenv
$ mkvirtualenv work

In virtualenv, its name is at the head of prompt and you can use pip freely in it.

(work)webees@ubuntu:~$ pip install Django
Freeze : confirm what packages are installed

(work)webees@ubuntu:~$ pip freeze
Django==1.6
argparse==1.2.1
wsgiref==0.1.2
Deactivate : get away from virtualenv

(work)webees@ubuntu:~$ deactivate
virtualenv with python3

Confirm the path to python3

$ which python3
/usr/bin/python3
Set path with -p option

$ mkvirtualenv -p /usr/bin/python3 python3
(python3)webees@ubuntu:~$ python -V
Python 3.2.3
Workon : switch virtualenv or confirm its exist.

$ workon 
python3
work
Rmvirtualenv : remove virtualenv

$ rmvirtualenv work

Done


This article will help you to install Python 2.7.13 on your Ubuntu, Debian and LinuxMint operating systems. At writing time of this article Python 3.4.5 latest stable version is available to download and install. To install Python 3.4.5 visit following article.

How to Install Python 3.4.3 on Ubuntu & LinuxMint

Install Required Packages

Use the following command to install prerequisites for Python before installing it.

$ sudo apt-get update
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

Download Python 2.7.13

Download Python using following command from python official site. You can also download latest version in place of specified below.

$ cd /usr/src
$ wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz

Now extract the downloaded package.

$ tar xzf Python-2.7.13.tgz

Compile Python Source

Use below set of commands to compile python source code on your system using altinstall.

$ cd Python-2.7.13
$ sudo ./configure
$ sudo make altinstall

make altinstall is used to prevent replacing the default python binary file /usr/bin/python.

Step 4: Check the Python Version

Check the latest version installed of python using below command

# python2.7 -V

Python 2.7.13

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment