pyslurm icon indicating copy to clipboard operation
pyslurm copied to clipboard

pyslurm import error

Open hokiegeek2 opened this issue 3 years ago • 2 comments

Details

  • Slurm Version: 20.8.11
  • Python Version: 3.9.7
  • Cython Version: 0.29.24
  • PySlurm Branch: main
  • Linux Distribution: Ubuntu 18.04

Issue

After successfully building (I think)...

image

...and installing pyslurm (I think)...

image

when I attempt to import pyslurm I get this error:

image

hokiegeek2 avatar Jan 27 '22 13:01 hokiegeek2

Also, when I attempt the pyslurm install from the 20.11.8 branch or tag I get the following version error:

image

hokiegeek2 avatar Jan 27 '22 13:01 hokiegeek2

pyslurm 20.11.8 install and run works fine for me. I think the "no module named pyslurm.pyslurm" error is simply due to cwd in pyslurm (which contains a folder pyslurm).

python3 -c 'import pyslurm; print(pyslurm.__version__)'
20.11.8.0
cd pyslurm-20.11.8-1/
python3 -c 'import pyslurm; print(pyslurm.__version__)'
ModuleNotFoundError: No module named 'pyslurm.pyslurm'

schluenz avatar Feb 14 '22 08:02 schluenz

As @schluenz hinted, the original import error stems from the fact that python, by default, always searches for modules/packages inside the current working directory first (see here). So if you do import pyslurm from the top-directory in the repo, you will receive this import error, because there is actually no pyslurm.py in the pyslurm directory

The import would probably work for a ordinary python project, but since pyslurm consists of almost only *.pyx files that have to be compiled first, it won't work. It would work with an editable install, or, since python 3.11 there is a new command-line flag -P that prevents prepending the cwd.

So importing the pyslurm library will work from anywhere but the top-directory in the git repo

tazend avatar May 21 '23 17:05 tazend