Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It is possible to write code that works for both major versions of Python, and it is the recommended strategy for maximum compatibility and flexibility. See the following page for a comprehensive list of compatible idioms. The easiest way to make sure your python 2 code can run on python 3 is to use automatic conversion tools such as futurize. Even if they are not perfect in all cases, they should take care of adapting the vast majority of your code base without too many bugs introduced. Futurize will also generate code that is compatible with both editions. See the quick start guide for instructions on how to use this tool.

Additionally, you may want to have a look at other tools and resources such as:

  • 2to3: it comes with the Python distribution, and it will attempt to convert 2.x source code into 3, but it may not generate code which is compatible with both.
  • Can I Use Python 3: This script takes in a set of dependencies and then figures out which of them are holding you up from porting to Python 3.
  • Six: a Python 2 and 3 compatibility library. It provides utility functions for smoothing over the differences between the Python versions with the goal of writing Python code that is compatible on both Python versions. See also nine,  which turns six upside down. You write your code using Python 3 idioms – as much as possible –, and it is the Python 2 “version” that is patched.
  • Supporting Python 3: An in-depth guide is a free, open source eBook that guides you through the process of adding Python 3 support, from choosing a strategy to solving your distribution issues. Using plenty of code examples, it guides you across the hurdles and shows you the new Python features.

Python 3 at ECMWF

Info

Both python and python3 modules can be loaded at the same time.

Python3 module IS NOT loaded by default, so do not forget to load it before running your scripts!

...

Note

Newest versions of the ECMWF packages and libraries support now both python 2 and 3. ecCodes python 3 support is, however, still considered BETA

When running on an ECMWF platform, all recent installations of ECMWF software packages and libraries can now be used with python 2.7 and 3.6. In order to work with the new python 3, you should:

...

For sustainability and maintainability reasons, some extra modules available in Python 2 may not be installed in the Python 3. If you need a module that is missing, please consider if you can use it through a virtual environment. This is particularly recommended if the module is being evaluated or tested, or if it's not going to be used widely at the centre. If in doubt, please get in touch with servicedesk@ecmwf.int. using the ECMWF Support Portal at https://support.ecmwf.int

Show If
groupecmwf

You may use the Python chat room to discuss any Python matter with your fellow Python enthusiasts.