Page tree

Python is becoming increasingly popular for developing control room applications. Support for control system related tasks is excellent, and a toolbox with useful functions and classes is slowly growing.

Programming Conventions

It is good practice to follow a small set of common rules when developing Python code for production use. We have collected these rules in a style guide.

Distribution, Packages, and Toolboxes

A single Python distribution, Anaconda with Python 3.7, 64 bits is supported across all platforms (Mac, Windows, Linux). Anaconda includes the most important packages like numpy, matplotlib, pyqt5. Additional packages can be used in virtual environments (see below). Control system bindings and various toolboxes from the HLC team have to be made accessible by setting the PYTHONPATH environment variable; look up your operating system below for information on how to find them.

  • PyDOOCS (import pydoocs): Native access to DOOCS is provided by pydoocs for Mac and Linux platforms. Additional information can be found here: Python Client Interface
  • PyTINE (import PyTine): The PyTine TINE bindings are currently the only way to access the control system from Python on Windows.
  • HLC Toolbox: Several useful Python modules created by the HLC team.

The Anaconda installation on control system Linux and Mac computers contains a number of packages selected by the HLC team. On other computers, users can create a similar setup as a virtual environment with the following command:

conda create --name hlc python=3.7 cx_oracle keras matplotlib numexpr numpy pandas pymongo pyqt pyqtgraph pytorch scikit-learn scipy seaborn sphinx

The following command can be used to enable such a custom environment:

conda activate hlc

To deactivate it again (and get back to the default Python installation):

conda deactivate hlc

App Installation

Python tools reside in ${HOME}/released_software/python, where ${HOME} is either /home/xfeloper for the XFEL or /home/ttflinac for FLASH. Writing to these directories requires doocsadm privileges. Installed Python tools must be traceable via a source code repository, preferably on the DOOCS GIT server. Installation is done with the script ${HOME}/released_software/scripts/release_software_package or similar tools. There is a launch command that makes sure that all the correct paths are set; start your main.py with: ${HOME}/released_software/scripts/pylaunch main.py

Mac Setup

Anaconda is installed under /opt/anaconda3. To make Anaconda your standard Python interpreter, add its bin directory to the beginning of your PATH, e.g. in your .bash_profile:

export PATH=/opt/anaconda3/bin:$PATH

There are several useful external modules you may want to include. For Python to find them, add them to your PYTHONPATH, e.g. in your .bash_profile:

export PYTHONPATH=/local/lib/python3.7:/local/tine/lib:/home/xfeloper/released_software/python/hlc_toolbox_common:/home/xfeloper/released_software/python/lib

Linux Setup

Anaconda is installed under /opt/anaconda3. To make Anaconda your standard Python interpreter, add its bin directory to the beginning of your PATH, e.g. in your .bash_profile:

export PATH=/opt/anaconda3/bin:$PATH

The PyTine bindings are installed under /usr/share/libtine/python/python3.7m on most systems. If they are not, have an admin install the Debian package for you:

apt-get install tine-python-anaconda

For Python to find the various external modules listed above, add them to your PYTHONPATH, e.g. in your .bash_profile:

export PYTHONPATH=/local/lib/python3.7:/usr/share/libtine/python/python3.7m:/home/xfeloper/released_software/python/hlc_toolbox_common:/home/xfeloper/released_software/python/lib

Windows Setup

The Anaconda Python package is available via NetInstall/DSM. Alternatively, you can download Anaconda yourself under http://continuum.io/downloads.

The PyTine bindings are distributed with the usual TINE installer, available via Netinstall/DSM for some, or via http://tine.desy.de/ for all (see Downloads/Windows Installer). For Python to find the PyTine module, you still need to set a PYTHONPATH environment variable that points to the directory containing PyTine.pyd (e.g. C:\tine\Python).

Integrated Development Environments (IDEs)

You can of course use your favorite text editor and the command line. Or check out one of these IDEs:

  • PyCharm (free version available for Windows, MacOS, Linux)
  • Visual Studio (free community edition can be used for DESY projects, but requires personal registration, Windows only)
  • Visual Studio Code
  • No labels