5

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?

5 Answers 5

8
  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/

3
  • but where is the source then? in what directory is it after having done 'apt-get source python' ?
    – IARI
    Jul 18, 2015 at 12:35
  • @IARI it is placed in the current working directory. Nov 29, 2016 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, 2016 at 19:44
2
  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.

2

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.

0

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.

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .