User Tools

Site Tools


software:python

Beginner tutorials

Style guide

Larics uses Googles's Python Style Guide for guidelines on organizing and structuring code.

Installing Python packages

Use binary packages, i.e. Installers on Windows and apt-get on Linux, if available. If you can't get binary releases, use pip to manage Python packages (as it supports uninstalling!).

On Windows

Note: On Windows, your first approach should always be to just grab the binary installers, if they are provided by the software maintainers. For packages that don't have binary releases, use the package management approach outlined below (note that the package managers instal “from source”, i.e., they download and build the sources for your particular platform).

Grab Setuptools, an older Python package manager, which doesn't support uninstalling. Make sure you grab the Setuptools corresponding to your Python version.

Install PIP. From the command line type:

easy_install pip

Now you can install Python packages simply by issuing the command:

pip install <package name>

To get additional usage options (e.g. uninstalling), try:

pip --help

For a GUI package manager, try Python Package Manager, a frontend for easy_install/pip.

IPython

Tips and tricks

Reloading changed modules

Use IPython :)

A nice quick tour of neat IPython features.

Overview of useful IPython commands.

To automatically reload changed modules:

%load_ext autoreload
%autoreload 2

For more info, check:

%autoreload?

Taken from here

Watch out with the %run command and changed modules! It seems that %run does not automatically do a deep reload. You have to manually do:

dreload(module)

Resetting the environment

Resetting the environment:

%reset

If you want to reload the pylab (numpy + matplotlib) environment:

% pylab

Debugging

Start debugging environment on error:

%pdb on

Profiling

OpenCV for Python

A brief howto for setting up OpenCV for Python can be found here.

Network programming

If you are designing both ends of the communication, ZeroMQ is the tool to use.

The asyncore library, which is part of Python's standard library, is a tool for doing simple network programming. A nice tutorial is available on Doug Hellman's blog. This library is possibly outdated.

Virtual environments

Packaging Python software

Documentation

Automatic documentation generation from docstrings (and more).

software/python.txt · Last modified: 2017/05/12 09:29 (external edit)