Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

5 Answers 5

  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/

share|improve this answer

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.

share|improve this answer
  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.

share|improve this answer

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.

share|improve this answer

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:

http://hg.python.org/cpython/file/a970054a93fb/Tools/demo

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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