Skip to content

Python Primer

Chris Meyer edited this page Sep 21, 2017 · 1 revision

Python applications such as Nion Swift use a variety of Python packages that need to be installed into Python.

Predefined packages (such as SciPy) are installed using one of several tools: pip, easy_install, or conda. Each of these will consult an online package repository (PyPI for the first two, conda for the latter), download the package, check version compatibility against all other packages, and perform the installation.

You can also remove packages with those same tools.

The Python Path

Python finds packages through the use of a Python path. You can see the configured Python path using a short Python script:

$ python
>>> import sys, pprint
>>> pprint.pprint(sys.path)

The Python path is configured by default when you install Python. Installing additional packages may also extend the path.

If you are developer, you may choose to extend the path to point to a development package. There are a few techniques, but the recommended way is to use a command:

$ pip install -e /path/to/development/package

Python Environments

Because each application may have unique requirements, Python also allows you to create separate environments containing packages particular to an application. The default environment is the root environment.

Additional environments can be created using virtual environments (https://docs.python.org/3/library/venv.html) or conda environments (https://conda.io/docs/user-guide/tasks/manage-environments.html).

Clone this wiki locally