Instructions from before the change to Anaconda are here, but they likely will not work with current versions of the source.

WARNING: As of December, 2020 we are finally approaching the first Python 3 release. The "master" branch of EMAN2/SPHIRE/SPARX should have relatively few bugs at this point. You may install both the last stable release from Fall, 2019 and the current Python 3 build simultaneously. If you follow the instructions below through step 10, you should have a fully functional Python 3 build.

Building EMAN2/SPARX/SPHIRE from Source

The EMAN2 source lives on GitHub, downloading the source is part of the instructions below. Do not download it yet!

These are the standard instructions for establishing a build and runtime environment for EMAN2/SPARX/SPHIRE on Linux and Mac. While the instructions look long, in reality it should only take 10-15 minutes to complete the entire process (with a decent network connection). This build uses Anaconda/Miniconda (DO NOT DOWNLOAD THE MOST RECENT VERSION FROM THIS LINK) for a working environment and most of the dependencies. Anaconda has become ubiquitous for Python and R-based scientific computing and education over the last decade. While it may be possible to build the system without using Anaconda, we do not recommend doing this, and cannot provide support for a non-Anaconda approach. If you follow the instructions below, you should have a painless source build very quickly.

Building on Windows is so complicated that we cannot provide generic instructions at this point in time.

Note that even with a source build it may be difficult to get this working on systems with very old operating system installs. We normally try to support OS versions as much as 5-7 years old. Please report any problems.

GPU Support (Linux Only!)

For features which support the GPU, please complete the standard source install instructions below, then follow the GPU instructions from the binary installation page.

Building and Installing EMAN2/SPHIRE/SPARX

Anaconda comes in two flavors Anaconda which is a full featured system with many libraries and capabilities built in, and Miniconda which is a stripped down version of the system. Both systems are the same, it is just a question of which packages come preinstalled. These instructions are based on the smaller Miniconda install. You may also have success with Anaconda, but a better approach may be to install Miniconda, then add in any extra packages you actually need.

We make use of the environment system in Anaconda to isolate EMAN2 dependencies from other Anaconda packages you may have installed. If you need to install other packages you wish to use in concert with EMAN2, you will need to install them within the EMAN2 environment. Be warned that sometimes installing another package may trigger a version change in one of EMAN2's dependencies, which may or may not be a problem, depending on which dependency it is. We strongly suggest getting the base EMAN2 installed and working first, before trying to install any additional packages within the same Anaconda environment.

Initial Setup and Build (one time)

  1. Remove/deactivate other Anaconda installs. If you do not have Anaconda/Miniconda (or another copy of EMAN2/SPARX/SPHIRE) already installed in your account, skip to step 2. If you DO have Anaconda or Miniconda installed in your account, you must ensure that any existing install you have is not active in your shell (not in PATH, no LD_LIBRARY_PATH or PYTHONPATH set). While it may also be possible to set up an environment for EMAN2 in your existing Anaconda install, you will need to know what you're doing, and adapt these instructions to your situation.

       1 echo $PATH
       2 # make sure no Anaconda/Miniconda/EMAN2 entries
       3 echo $LD_LIBRARY_PATH
       4 echo $PYTHONPATH
       5 # ideally, both return nothing. If it set to something it is possible that it may interfere with Anaconda
       6 # strongly suggest at least during the install, ''unset'' both of these. After installation you can test
       7 # to see if they cause any issues
  2. Download and install this specific version (4.8.3) of Miniconda: Linux or MacOSX

       1 bash <Miniconda-installer>
       3 # There are a variety of options you can use, but the default command above is sufficient in most cases
       4 bash <Miniconda-installer> --help

    and follow the prompts. When you see Do you wish the installer to initialize Miniconda3 by running conda init?, say no, then move on to the next step.

  3. Initialize conda for shell interaction. These instructions will depend on what shell you use. The default on most systems is bash. If you use a different shell ( tsch, zsh, ... ), you will need to take this into account:

       1 # for bash-like shells, such as bash and zsh
       2 source <miniconda-path>/etc/profile.d/
       4 # for csh-like shells, such as csh and tcsh:
       5 source <miniconda-path>/etc/profile.d/conda.csh
       7 # <shell-name> is bash, fish, powershell, tcsh, xonsh or zsh
       8 conda init <shell-name>
      10 # we suggest the following, meaning you will need to use ''conda activate'' after logging in before using EMAN2
      11 conda config --set auto_activate_base False

    As it says after you run this command, you will need to close and reopen your shell/terminal for it to take effect. This command modified your shell initialization so the conda activate command can be used properly. For more information on conda-init and activation, see Environment Activation.

    MacOS Users (bash only)

    On MacOS, this modifies ~/.bash_profile. If you have a ~/.profile startup file, creation of ~/.bash_profile will prevent ~/.profile from being read. A simple solution is to source .profile within .bash_profile.

    For differences between login- and non-login shells and order of reading the startup files on Mac OSX, see,

  4. Configure and update conda.

       1 # Automatic Anaconda/Miniconda updates may cause things to break, so we suggest making all package upgrades explicitly
       2 # The current version verified to work with EMAN is '''conda 4.9.1'''
       3 conda config --set auto_update_conda False
       5 # Flexible channel priority works better for eman-deps
       6 conda config --set channel_priority flexible
       8 # Update base environment to get the latest conda
       9 conda update --all -n base
  5. Create a new environment with EMAN2 dependencies. eman2 below is the name of the environment. You may make this whatever you like, as long as you remember to use the same name when doing conda activate. Note that this name will appear as part of your prompt when activated, so you may want to keep it short.

       1 #In order to use the latest version of eman-deps-dev check the latest version here:
       2 # By default the newest version is used.
       3 conda create -n eman2 eman-deps-dev -c cryoem -c defaults -c conda-forge

    If you wish to see the list of conda dependencies that eman-deps is built from, look here.

    MacOS Big Sur Users

    The new Big Sur MacOS release (fall 2020) broke some things in Python, which are only now (Dec 2020) getting fixed. These fixes have not yet made their way into Anaconda. If you experience an error similar to "Unable to load OpenGL library", this quick fix seems to provide a temporary solution until Anaconda gets the necessary updates:

    You need to go into your miniconda3 or anaconda3 folder and find this file (the path may be slightly different on your install, but you should be able to find it):


    Around line 80 you should find a line like:

    fullName = util.find_library( name )

    change this line to:

    fullName = '/System/Library/Frameworks/' + name + '.framework/' + name

    (important to use 8 spaces before fullName, not a <tab>)

  6. Get EMAN code from GitHub:cryoem/eman2.

       1 cd <path-where-you-want-eman2-source>   # eg - $HOME/src
       2 git clone # this will create an eman2 folder containing the current source code from the master branch
  7. Create a build directory (out-of-source builds are recommended).

       1 mkdir <build-directory> # eg- $HOME/src/eman2-build
  8. Activate your environment. If you used a different name above, use it here too.

       1 conda activate eman2
  9. Checkout source code and pull from the remote.

       1 cd <source-directory>  # <path-where-you-want-eman2-source>/eman2
       2 git fetch --all --prune
       3 git checkout master
  10. Ensure you have OpenGL
    • EMAN2 uses OpenGL (via PyQt) for all of its graphics. OpenGL installation depends on OS variant and, for example, whether you are using proprietary NVidia drivers under Linux. You will need to have OpenGL set up on your machine as a whole before continuing. On the Mac, you should already have this with XCode. On Linux with an NVidia driver you will likely also need to install the Mesa header files. If you aren't sure how to set up OpenGL, Google can probably help.

  11. Build EMAN

    1. CMake

         1 cd <build-directory>
         2 # on Mac:
         3 cmake <source-directory>   # - eg $HOME/src/eman2, optionally add -DCMAKE_VERBOSE_MAKEFILE
         5 # on Linux:
         6 cmake <source-directory> -DENABLE_OPTIMIZE_MACHINE=ON  # - eg $HOME/src/eman2, optionally add -DCMAKE_VERBOSE_MAKEFILE
      • cmake-gui

        • If you use cmake-gui, since conda is not in PATH anymore, cmake will fail to find the environment directory. In that case set CONDA_PREFIX to your conda environment directory manually.

        • Make sure to delete any cmake variables that cmake already found, variables like *_LIBRARY or similar, *_INCLUDE_PATH or similar, CONDA_EXECUTABLE, CMAKE_INSTALL_PREFIX and any variables that are expected to contain conda environment related values.
        • Configure and generate.
      • ccmake

        • If you use ccmake, you may get an error related to OpenGL. If this happens try quitting ccmake and running it again.

    2. Make

         1 make -j 8
         2 make install
  12. Note that the make -j 8 above will compile using 8 threads. On some machines omitting the 8 will compile faster and cause no problems, and if you have more than 8 threads on your machine, you can increase the number.

  13. Test your installation. We do NOT recommend this for end-users. A failure does NOT necessarily indicate an installation problem. These commands are mostly provided for developers actively changing the code to detect harmful changes before committing them. Sometimes the system will have a failing test, and still be absolutely fine.

       1 make test          # if everything passes you are fine, if there are failures, please ask. A failure does not necessarily mean a bad build, it may be a problem with the test.
       2 make test-verbose  # verbose test output to help to identify specific failures

For debugging and reporting, see Debugging and Reporting.

Python 2 Environment

If you wish to use EMAN2.31 or earlier, you will need to set up a separate Python 2 environment. This can be done from within the same Anaconda install you used above. Create and activate a conda environment with the following commands:

  1. Create a conda environment. You need to do this only once.
       1 conda create -n py2 eman-deps=16.1 cmake=3.14 boost=1.66 -c cryoem -c defaults -c conda-forge
    You can replace "py2" with another name for the environment.

If you encounter errors in cmake, you may need to remove your CMakeCache.txt file and try cmake again.

  1. Activate the environment.
    1. If you are in the "base" environment, activate your new environment with python 2.
         1 conda activate py2
    2. If you are in your "eman2" environment, first deactivate it, then activate "py2".
         1 conda deactivate
         2 conda activate py2
  2. Checkout source code and pull from the remote. Code on "master" is python 3 only, to checkout python 2, use tag "python2". Note that "python2" is read-only and can't be updated by pushing to it.

       1 cd <source-directory>  # <path-where-you-want-eman2-source>/eman2
       2 git fetch --all --prune
       3 git checkout python2   # this is the tag pointing to the last python 2 code

For debugging and reporting, see Debugging and Reporting.

EMAN Daily Development (updating code, etc)

When you start a new shell, these are the steps you will need to take before running EMAN2 programs or compiling the system:

  1. Activate your environment. If you used a different name above, use it here too.

       1 conda activate eman2
  2. Update. Periodically you should update your source using standard git techniques. If you are not modifying EMAN, just compiling from source, you just need to periodically:

       1 cd <source-directory>  # <path-where-you-want-eman2-source>/eman2
       2 git pull
  3. Build EMAN

       1 cd <build-directory>
       2 make -j
       3 # if there are build problems, before reporting them, try rerunning cmake (above) first
       4 make install
  4. Other Environments. To switch to another conda environment (stop working with EMAN2), first deactivate your current environment.

       1 conda deactivate

For debugging and reporting, see Debugging and Reporting.

Debugging and Reporting

Please, include the output of the following items when reporting a problem.

  1. If make test fails, run the verbose tests.

       1 make test-verbose
  2. In the source directory, run
       1 git status
       2 git log -1
  3.    1 conda info -a
       2 conda list
       5 # This is not always needed.
       6 # It will print urls of packages and should be needed
       7 # only if the previous output is not sufficient.
       8 conda list --explicit
  4. In the build directory, run
       1 cmake . -LA


It could be better to record the session via script. This, also, records the commands.

  1.    1 script filename.txt
       3 conda activate eman2
       5 cd <source-dir>
       6 git status
       7 git log -1
       9 cd <build-dir>
      10 rm CMakeCache.txt
      11 cmake <source-dir>
      12 make clean
      13 make -j
      14 make install
      15 make test-verbose
      17 conda info -a
      18 conda list
      19 conda list --explicit
      21 cmake . -LA
      23 conda deactivate
      25 exit # or Ctrl+D
  2. Send filename.txt.

Linux Clusters

The approach above will install EMAN with a precompiled version of OpenMPI, which may or may not work with the batch queuing system on your cluster. If it does not work, the symptom will be that MPI parallel jobs will use only a single node, no matter how many you have allocated in your job. Currently, we do not have alternative OpenMPI installation instructions.

EMAN2/COMPILE_EMAN2_ANACONDA/2.39 (last edited 2020-12-29 02:16:00 by TunayDurmaz)