In this instruction we explain how to install Python and all the necessary Python packages to be able to run BornAgain simulations via Python scripting.
We advertise this as an instruction for advanced users. However, it provides a much more lightweigth and cleaner environment than the bulky Python installation using Anaconda explained here.
Download and install Python 3.9 64-bit version from official site.
This is actually the most complicated step since the
default download button leads to a download of the 32-bit version which will not work with BornAgain.
To download the correct version, click on the
Windows link marked on sthe creenshot below.
On the new page you will find a list of
Windows installers. Select the
Windows x86-64 executable installer. Make sure that you are in
the section corresponding to Python 3.9
Run the installer. Please select
Add Python 3.7 to PATH at the bottom of the screen and then push
Adding Python to the PATH is an important step to be able to use Python from the command shell and various code editors.
numpy to be installed in site-packages of your Python distribution.
Start a Windows command shell by typing
cmd in the Windows
In the new opened window type
pip install matplotlib numpy
Pip is a package manager which is used in the Python world to manage packages in an existing Python installation.
pip install matplotlib numpy starts the installation of the
matplotlib library for plotting and the
numpy library for matrix manipulation.
pipcommand is not found on the system, this means that you have forgotten to add Python to the PATH as explained above.
When the installation is complete the window should look like the screenshot below.
At this point Python and all the required dependencies are successfully installed.
In this scenario you have installed Python to your local home directory and you have added
Python to the system PATH. This approach has the advantage that your Python is integrated with the Windows installation and
you can use it from any Windows command shell or use it together with any integrated development environment, like
The disadvantage is that this approach can be safely used only if you have a single Python installation on your system. The setup of multiple Python versions on a system goes far beyond the scope of this tutorial.
To validate that BornAgain is working nicely together with the installed Python,
start a Windows command shell by typing
cmd in the Windows
To validate the BornAgain installation, type
pythonto start the Python interpreter
import bornagainas a first command
print(bornagain.GetVersionNumber())to print the BornAgain version number on the screen.
If no errors are displayed and you also see the BornAgain version number printed on the screen, your installation is correct.
To run a BornAgain example from the command line, launch a command shell again and type (or copy-and-paste) the command below to see a scattering image appearing on the screen.
The used path implies that BornAgain was installed to the default location. If this was not the case, you will have to adjust the path to the BornAgain Python example accordingly.
Tip:while typing long commands in the command shell you can push the
TABkey and Windows will attempt to autocomplete long directory names.
This kind of manual launching of Python scripts is not very convenient for regular usage and should be considered rather as another validation step.
We have provided two more step-by-step tutorials to explain how to run BornAgain examples in a convenient manner using one of two integrated development environments.