Solving Numpy error in packaging ChimeraX

Hello, I am trying to package this python application, ChimeraX; however, I keep getting a numpy error when I attempt to run it. Please see code and then error message below. I have tried everything that I can think of to solve the problem. The libfortran file in question lives in the numpy.lib folder in ChimeraX.

{ stdenv, gzip, lib, buildFHSEnv }:

let
  pname = "chimerax";
  version = "1.7.1"; # Adjust to the correct version

  chimerax = stdenv.mkDerivation rec {
    inherit pname version;
    # src = fetchzip {
    #   url = "https://www.cgl.ucsf.edu/chimerax/cgi-bin/secure/chimerax-get.py?file=1.7/linux/ChimeraX-${version}.tar.gz";
    #   sha256 = "sha256-h8mMdDOAyTlH8q9OiXM5iDAEg/LqClKLkm/COdigJS0=";
    # };

    src = ./ChimeraX-1.7.1.tar.gz; 

    dontBuild = true;
    buildInputs = [ gzip ];

    unpackPhase = ''
      gunzip -c $src > ${pname}.tar
      tar -xf ${pname}.tar
    '';

    installPhase = ''
      mv ${pname}-${version} $out
      chmod +x $out/bin/ChimeraX
    '';
  };
in
buildFHSEnv {
  name = pname;
  targetPkgs = pkgs: [
    chimerax
    # pkgs.python311Packages.pip
    # pkgs.python311Packages.virtualenv
    # pkgs.libgcc
    # pkgs.gcc
    # pkgs.pkg-config
    # pkgs.cmake
    # pkgs.libffi.dev
    # pkgs.binutils
    # pkgs.coreutils
    # pkgs.expat
    # pkgs.libz
    # pkgs.glib.dev
  ];
  # multiPkgs = pkgs: with pkgs; [
  #   gcc
  #   libgcc
  #   binutils
  #   coreutils
  # ];
  profile = ''
    export PYTHONPATH=/nix/store/rap39wzrgbbahpizxz6ydxja30zx7q0b-python3-3.11.9/lib/python3.11/site-packages:/nix/store/ylvsb39l0wq5q6xdphrq35an6dxqhjw9-python3.11-numpy-1.26.4/lib/python3.11/site-packages:/nix/store/7hnr99nxrd2aw6lghybqdmkckq60j6l9-python3-3.11.9/lib/python3.11/site-packages
    export LIBRARY_PATH=/usr/lib:/usr/lib64:$LIBRARY_PATH
    export PATH=/usr/bin/gcc:$PATH
  '';
  # runScript = "ChimeraX";
  runScript = "ChimeraX";
  meta = with lib; {
  description = "ChimeraX - next-generation molecular visualization program";
  homepage = "https://www.cgl.ucsf.edu/chimerax/";
  platforms = platforms.linux;
  };
}

Error message below:

NOTE: Traceback (most recent call last):
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/core/init.py”, line 23, in
from . import multiarray
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/core/multiarray.py”, line 10, in
from . import overrides
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/core/overrides.py”, line 8, in
from numpy.core._multiarray_umath import (
ImportError: libgfortran-040039e1.so.5.0.0: cannot open shared object file: No
such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 198, in _run_module_as_main
File “”, line 88, in _run_code
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/chimerax/core/main.py”, line 1069, in
exit_code = init(sys.argv)
^^^^^^^^^^^^^^
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/chimerax/core/main.py”, line 568, in init
sess = session.Session(app_name,
^^^^^^^^^^^^^^^^^^^^^^^^^
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/chimerax/core/session.py”, line 490, in init
from chimerax.graphics.gsession import register_graphics_session_save
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/chimerax/graphics/init.py”, line 48, in
from .opengl import Texture, Lighting, Material
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/chimerax/graphics/opengl.py”, line 2596, in
from numpy import uint8, uint32, float32
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/init.py”, line 139, in
from . import core
File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/core/init.py”, line 49, in
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html  

Please note and check the following:

  • The Python version is: Python3.11 from “/usr/bin/ChimeraX”
  • The NumPy version is: “1.25.1”

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libgfortran-040039e1.so.5.0.0: cannot open shared object
file: No such file or directory

BUG: ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

Troubleshooting — NumPy v2.1.dev0 Manual

Please note and check the following:

  • The Python version is: Python3.11 from “/usr/bin/ChimeraX”
  • The NumPy version is: “1.25.1”

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libgfortran-040039e1.so.5.0.0: cannot open shared object
file: No such file or directory

File
“/nix/store/jpggf201nxv2lx7imcsawpghz1w5gm73-chimerax-1.7.1/lib/python3.11/site-
packages/numpy/core/init.py”, line 49, in
raise ImportError(msg)

See log for complete Python traceback.

https://www.rbvi.ucsf.edu/chimerax/docs/devel/dependencies.html
there seem to be dependencies you have not included, pretty sure pip and venv are done in a nix-y way, so i’m not exactly sure as to how to do it, but you probably forgetting that. Apologies if i am not very helpful.

I appreciate your help! I could be wrong, but I am pretty sure that those dependencies are building ChimeraX. I probably need to package ChimeraX to be built from source, but this is probably beyond my capacity at this time. I am hoping that there was some standard issue for built python applications, but if this turns out to be an issue niche to ChimeraX, it might be beyond my capacity to overcome.

I am going to assume you already have looked into this and it isn’t possible for you to use it for your usecase

Edit: I did just realise you want to package Chimera. It might be easier, let me look into it.

Edit 2: Options for packaging a complex (py)QT application: ChimeraX - #2 by moritzschaefer
this might be useful. it is a very finicky workaround, but it works

1 Like

GODS SMITE ME

No, no I had not yet found this. Let’s see if it works!

do update me, would love to know.