I have Python 2.7 installed for learning purposes (I'm a starting programmer reading 'Learn Python The Hard Way') and wanted to know how some things were done.

I installed it from Synaptic and want to know the folder that the source code is in. Can anyone help me here?

  1. If you enable the source code repositories in "Software sources" application (software-properties-gtk), you can download the latest python source that is related to the package:

    apt-get source python

    You can do that for any ubuntu/debian package.

  2. You can always google your way to the source code: http://www.python.org/download/releases/

  • but where is the source then? in what directory is it after having done 'apt-get source python' ?
    – IARI
    Jul 18 '15 at 12:35
  • @IARI it is placed in the current working directory. Nov 29 '16 at 19:39
  • 2
    Note that the python source is pretty minimal and probably not what you want. Try python3.5 instead, it has CPython and the standard library. Nov 29 '16 at 19:44
  1. Try from command line:

    dpkg -L python2.7

    It shows you where the files are installed in your system.

  2. Try to install the package python2.7-examples. It contains many useful examples for learning purposes.


It's not clear to me what source you are asking for. Python is installed by default on Ubuntu and the 2.7 version is installed on Ubuntu 12.04 (and I believe earlier versions). Is it python 2.7 that you installed with synaptic? Ubuntu uses CPython, so named because it is written in C. Therefore its source is not put on your computer unless you ask for it. medigeek has posted a helpful answer that will tell you how to download it.

Ubuntu uses python for many of its packages, for example ubiquity (the Ubuntu installer), Jockey (Additional Drivers), and Startup Disk Creator. Since packages written in python are distributed in source form and compiled on installation, you can examine these packages on your system. For example, jockey has source code at /usr/share/pyshared/jockey/. /usr/share/pyshared has python source for lot's of packages (almost 300 on my system).

The source for python 2.7 itself can be found at http://hg.python.org/cpython. Other versions of python have had their source imported onto Launchpad. You can see them here. Click on one you want to see and you can then click "Browse the Code".

Good luck learning Python.


Other answers have pointed you toward the source code for upstream Python.

Downstream Python (the specific versions provided in Ubuntu) has source code that you can browse here.

By the way, if you're just starting to learn Python, you should almost certainly focus primarily on Python 3.


I'm assuming you are looking for the demos and simple example programs that ship with python. You can install the python source package using:

cd /somewhere/you/want/source/code/
sudo apt-get source python

The demo programs will be in the Tools/demo folder after it finished installing.

Alternately, you can just browse those directly online without installing anything:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.