Search
This page provides basic walkthroughs and tutorials for the programing language Python.
We do not cover all aspects of programming in Python. We provide some starting points and expect you find more. We recommend [Wentworth2012] as your main teaching material. The more advanced book [Pilgrim2009] may perhaps be more interesting for experienced programmers
If you are using Linux, Python is most likely already installed. Otherwise, install it using your SW manager (like Synaptic). Python is also quite likely to be already installed in Mac OS X. Try running terminal and write which python. In the case of MS Windows, it will not be installed. You will have to install it.
In a terminal window (Linux or OSX) you can check:
[182] python3.2 Python 3.2.2 (default, Mar 15 2012, 17:46:27) [GCC 4.5.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
[53] python3 Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
You can quit by Ctrl-d, or typing exit()
Ctrl-d
exit()
We will use the 3.6.x version. Please be aware that on many machines Python 2.7.x is still often the default Python interpreter. Python 3 is not fully compatible with Python 2.x. There is a code converter which makes the possible transition easier. Many important libraries have been already ported to Python 3.
You might also be interested by python virtual environments that can be used by installing virtualenv, as well as virtualenvwrapper to make it more practical to use.
Virtual environment enable you to create an environment for each assignment, or each course, so that each python environment is independent from the others, and the installed libraries do not conflict, keeping them also from conflicting with your system's python default version (in particular if you are on linux). For exemple, you could create an environment with Python 2.7 and numpy 3.0 for a course, then another environment with Python 3.0 and numpy 3.0 for a second course, and again an environment with Python 3.0 and numpy 3.2 for a third course. Without virtual environment, this would be difficult to manage (especially the case where you need different versions of the same library for different projects). With virtual environments, it is extremely easy.
After you install both virtualenv and virtualenvwrapper you can create a new environment (you'll need to add parameters if you want the virtual environment to use a different version of python than your system default's, check the documentation of virtualenvwrapper) using:
mkvirtualenv ENVIRONMENT_NAME
rmvirtualenv ENVIRONMENT_NAME
workon ENVIRONMENT_NAME
Once inside the virtual environment, you can use:
pip install LIBRARY_NAME
Virtual environments can easily be setup with Visual Studio Code, or other IDEs.
A single environment should be enough for all of this course's assignments.
Be careful to never use sudo when installing python libraries from inside a virtual environment, as it will instead install them on your OS' python.
sudo
Credits to the 'be5b33prg' course for most of this tutorial page.