Installing PyNE on Windows via WSL

4 minute read

Published:

Although PyNE is officially only supported for Linux and Mac, it is possible to build and use it on Windows using the Windows Subsystem for Linux (WSL) and the Ubuntu terminal app from the Microsoft Store. These instructions describe how to install a basic PyNE build (no MOAB, DAGMC or OpenMC interfaces) on Windows via WSL. They presume only some basic knowledge on using Linux and Windows command lines. They were written for Windows 10 (1909), Ubuntu 20.04 and PyNE 0.7.3 - mileage for other releases may vary.

Step 1 - Enable WSL in Windows

Open Windows PowerShell with administrator privileges (right click: Run as administrator) and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

This enables WSL 1 in Windows. Now restart your PC.

(Or you could continue to update to WSL 2 at this point by following these instructions. WSL 2 offers more advanced features that might be useful to you, such as GPU support, but they are not necessary for PyNE).

Step 2 - Install Ubuntu 20.04 LTS from the Microsoft Store

From the Microsoft Store app, search for Ubuntu and install the Ubuntu 20.04 LTS app.

Step 3 - Run Ubuntu 20.04 LTS and install libraries needed by PyNE

Run the Ubuntu 20.04 LTS app for the first time from the Windows Start menu, wait for it to set itself up, then enter a UNIX username and a password. Run the following commands in the terminal:

sudo apt update
sudo apt upgrade
sudo apt install python3-pip build-essential cmake gfortran libblas-dev liblapack-dev libeigen3-dev libhdf5-dev hdf5-tools
pip3 install --user numpy==1.17.4 scipy cython nose tables matplotlib future

This will install the libraries needed for a basic build of PyNE.

Now edit the .bashrc file using a text editor (nano, emacs, vim etc.) and add the following commands to the end of the file:

alias pip=pip3
alias python=python3
export PATH="$HOME/.local/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/.local/lib:/usr/lib/x86_64-linux-gnu/hdf5/serial:$LD_LIBRARY_PATH"

Close the Ubuntu terminal.

Step 4 - Download the PyNE source code

Open your favourite browser in Windows and download a .tar.gz file containing the PyNE source code from https://github.com/pyne/pyne/releases. The latest release at the time of writing is 0.7.3.

Step 5 - Copy the source code to Ubuntu, unpack, and build PyNE

Reopen a Ubuntu 20.04 LTS terminal window and copy the source tarball into the Ubuntu WSL file system via:

cp /mnt/c/DOWNLOAD_DIR/pyne-0.7.3.tar.gz .

Edit the drive letter and DOWNLOAD_DIR as appropriate to match where you downloaded the source file to. Unpack the source code and navigate into the source directory via:

tar -xf pyne-0.7.3.tar.gz
cd pyne-0.7.3/

Now build PyNE and install locally:

python setup.py install --user

Subject to build being successful, you can now run the following commands to make the nuclear data:

cd
nuc_data_make

An optional final step here is to run the tests:

cd pyne-0.7.3/tests/
./travis-run-tests.sh

Step 6 - Using PyNE in Python on WSL

You should now be able to use PyNE within Python on the Ubuntu 20.04 LTS app, e.g.:

>>> from pyne import data
>>> data.half_life("H-3")
388789632.0

Notes and alternative Windows install options [Updated June 06, 2021]

PyNE can be a little finicky to build, but persistence pays off. If you encounter any errors during builds, the Issues and PR sections of the PyNE Github repo, and the pyne-dev and pyne-users mailing lists are great sources of information.

The above instructions were based on the PyNE Ubuntu Install Scripts from https://github.com/pyne/install_scripts. An alternative starting from Step 3 onwards would be to download and run the ubuntu.sh install script available from that repository. This will install MOAB, DAGMC and OpenMC as well.

Another alternative that is easier than compiling from source is to install Anaconda on WSL, then install PyNE from conda-forge. See discussion on this option in these threads on the pyne-dev mailing list.

Finally, Gurdeep Kamal (Tokamak Energy) reported on the MCNP users mailing list that PyNE can be installed on Windows using the VirtualBox image.