jdkloe / pybufr-ecmwf

a python module that allows reading and writing BUFR formatted files, where BUFR stands for Binary Universal Form for the Representation of meteorological data.
Other
29 stars 12 forks source link

ModuleNotFoundError: No module named 'ecmwfbufr' #20

Closed sebhahn closed 4 years ago

sebhahn commented 4 years ago

In our internal continuous integration tests we experience occasionally the error ModuleNotFoundError: No module named 'ecmwfbufr'. We install pybufr-ecmwf via pip on a linux VM. However, sometimes it runs through without any exception - with the same settings though.

Full stack trace:

     Complete output (129 lines):
     running install
     running build
     build: self.user_options =  [('build-base=', 'b', 'base directory for build library'), ('build-purelib=', None, 'build directory for platform-neutral distributions'), ('build-platlib=', None, 'build directory for platform-specific distributions'), ('build-lib=', None, 'build directory for all distribution (defaults to either build-purelib or build-platlib'), ('build-scripts=', None, 'build directory for scripts'), ('build-temp=', 't', 'temporary build directory'), ('plat-name=', 'p', 'platform name to build for, if supported (default: linux-x86_64)'), ('compiler=', 'c', 'specify the compiler type'), ('parallel=', 'j', 'number of parallel build jobs'), ('debug', 'g', 'compile extensions and libraries with debugging information'), ('force', 'f', 'forcibly build everything (ignore file timestamps)'), ('executable=', 'e', 'specify final destination interpreter path (build.py)'), ('preferred-fortran-compiler=', None, 'name of preferred fortran compiler to be used'), ('preferred-c-compiler=', None, 'name of preferred c compiler to be used'), ('fortran-compiler=', None, 'name and full path of fortran compiler to be used'), ('fortran-ld-library-path=', None, 'path in which shared objects can be found that are needed by the choosen fortran compiler'), ('fortran-flags=', None, 'flags to be passed to the fortran compiler'), ('c-compiler=', None, 'name and full path of c compiler to be used'), ('c-ld-library-path=', None, 'path in which shared objects can be found that are needed by the choosen c compiler'), ('c-flags=', None, 'flags to be passed to the c compiler')]
     build: self.preferred_fortran_compiler =  gfortran
     build: self.preferred_c_compiler =  gcc
     running build_py
     creating build
     creating build/lib.linux-x86_64-3.6
     creating build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/__init__.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/bufr.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/raw_bufr_file.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/bufr_interface_ecmwf.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/run_f2py_tool.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/custom_exceptions.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/bufr_table.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/bufr_template.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     copying pybufr_ecmwf/helpers.py -> build/lib.linux-x86_64-3.6/pybufr_ecmwf
     running egg_info
     writing pybufr_ecmwf.egg-info/PKG-INFO
     writing dependency_links to pybufr_ecmwf.egg-info/dependency_links.txt
     writing top-level names to pybufr_ecmwf.egg-info/top_level.txt
     reading manifest file 'pybufr_ecmwf.egg-info/SOURCES.txt'
     writing manifest file 'pybufr_ecmwf.egg-info/SOURCES.txt'
     creating build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/C0000000000098015001.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/D0000000000098015001.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/B0000000000098015001.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/GENERIC_SCAT_BUFR_TABLE_C.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/GENERIC_SCAT_BUFR_TABLE_D.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     copying pybufr_ecmwf/alt_bufr_tables/GENERIC_SCAT_BUFR_TABLE_B.TXT -> build/lib.linux-x86_64-3.6/pybufr_ecmwf/alt_bufr_tables
     running build_ext
     building 'pybufr_ecmwf.ecmwfbufr' extension
     initiating build in dir:  /tmp/pip-install-uy1hgito/pybufr-ecmwf/build/lib.linux-x86_64-3.6/pybufr_ecmwf
     base_build_dir =  /tmp/pip-install-uy1hgito/pybufr-ecmwf
     Entering installation sequence:
     Using bundled library copy...
     Executing command:  cp /tmp/pip-install-uy1hgito/pybufr-ecmwf/ecmwf_bufr_lib_sources/bufrdc_000409.tar.gz ./ecmwf_bufr_lib
     Executing command:  cd ./ecmwf_bufr_lib;tar zxf bufrdc_000409.tar.gz
     copied file: handle_stdout.F
     copied file: retrieve_settings.F
     copied file: set_nokey.F
     added file handle_stdout.F to the sources list
     added file retrieve_settings.F to the sources list
     added file set_nokey.F to the sources list
     selection fortran compiler
     ==>input: self.fortran_compiler =  None
     ==>input: self.preferred_fortran_compiler =  gfortran
     Executing command:  which gfortran
     selection fortran compiler
     ==>result: self.fortran_compiler_to_use =  gfortran
     selection c compiler
     ==>input: self.c_compiler =  None
     ==>input: self.preferred_c_compiler =  gcc
     Executing command:  which gcc
     selection c compiler
     ==>result: self.c_compiler_to_use =  gcc
     Using: gfortran as fortran compiler
     Using: gcc as c compiler
     Creating ECMWF-BUFR config file:  ./ecmwf_bufr_lib/bufrdc_000409/config/config.linux_compiler
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/./Makefile
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/bufrdc/Makefile
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/bufrtables/Makefile
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/pbio/Makefile
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/fortranC/Makefile
     creating:  ./ecmwf_bufr_lib/bufrdc_000409/examples/Makefile
     Executing command:  gfortran -fno-second-underscore -O -Dlinux -fPIC -o pybufr_fortran_test_program pybufr_fortran_test_program.F90
     Executing command:  ./pybufr_fortran_test_program
     Fortran compilation test successfull...
     Executing command:  gcc -O -fPIC -o pybufr_c_test_program pybufr_c_test_program.c
     Executing command:  ./pybufr_c_test_program
     c compilation test successfull...
     Executing command:  gcc -O -fPIC -o GetByteSizeInt GetByteSizeInt.c
     Executing command:  ./GetByteSizeInt
     Executing command:  gcc -O -fPIC -o GetByteSizeLong GetByteSizeLong.c
     Executing command:  ./GetByteSizeLong
     Executing command:  gfortran -fno-second-underscore -O -Dlinux -fPIC -o GetByteSizeDefaultInteger GetByteSizeDefaultInteger.F90
     Executing command:  ./GetByteSizeDefaultInteger
     Executing command:  cd ./ecmwf_bufr_lib/bufrdc_000409;make ARCH=linux CNAME=_compiler R64= A64= 2>1 > bufrdc_build.log
     Build seems successfull
     compilation of BUFR library finished
     Entering wrapper generation sequence:
     Executing command:  python3 ./run_f2py_tool.py --overwrite-signature  --build-dir f2py_build -m ecmwfbufr -h signatures.pyf ./ecmwf_bufr_lib/bufrdc_000409/bufrdc/*.F ./ecmwf_bufr_lib/bufrdc_000409/pbio/pbbufr.F 2>1 > f2py_build.log
     Fixing array size definitions in signatures definition ...
     Using intlen =  8  to build the pbio interface
     Inserting hardcoded interface to pbio routines in signatures file ...
     Executing command:  python3 ./run_f2py_tool.py --build-dir f2py_build --f90flags='-fno-second-underscore -O -Dlinux -fPIC' --f77flags='-fno-second-underscore -O -Dlinux -fPIC' --fcompiler=gfortran ./f2py_build/signatures.pyf -L./ -lbufr -c 2>1 >> f2py_build.log
     a python wrapper to the ECMWF BUFR library has been generated
     compilation of library wrapper finished
     extracting library constants
     Traceback (most recent call last):
       File "<string>", line 1, in <module>
       File "/tmp/pip-install-uy1hgito/pybufr-ecmwf/setup.py", line 410, in <module>
         provides=["pybufr_ecmwf"])
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/core.py", line 148, in setup
         dist.run_commands()
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/dist.py", line 955, in run_commands
         self.run_command(cmd)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/dist.py", line 974, in run_command
         cmd_obj.run()
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
         return orig.install.run(self)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/command/install.py", line 545, in run
         self.run_command('build')
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/cmd.py", line 313, in run_command
         self.distribution.run_command(command)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/dist.py", line 974, in run_command
         cmd_obj.run()
       File "/tmp/pip-install-uy1hgito/pybufr-ecmwf/setup.py", line 119, in run
         _build.run(self)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/command/build.py", line 135, in run
         self.run_command(cmd_name)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/cmd.py", line 313, in run_command
         self.distribution.run_command(command)
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/dist.py", line 974, in run_command
         cmd_obj.run()
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/command/build_ext.py", line 339, in run
         self.build_extensions()
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
         self._build_extensions_serial()
       File "/root/miniconda/envs/warp_h_nrt_env/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
         self.build_extension(ext)
       File "/tmp/pip-install-uy1hgito/pybufr-ecmwf/setup.py", line 318, in build_extension
         ibi.build()
       File "/tmp/pip-install-uy1hgito/pybufr-ecmwf/build_interface.py", line 888, in build
         self.extract_constants()
       File "/tmp/pip-install-uy1hgito/pybufr-ecmwf/build_interface.py", line 1874, in extract_constants
         import ecmwfbufr
     ModuleNotFoundError: No module named 'ecmwfbufr'
     ----------------------------------------
 ERROR: Command errored out with exit status 1: /root/miniconda/envs/warp_h_nrt_env/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-uy1hgito/pybufr-ecmwf/setup.py'"'"'; __file__='"'"'/tmp/pip-install-uy1hgito/pybufr-ecmwf/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-937_0s73/install-record.txt --single-version-externally-managed --compile --install-headers /root/miniconda/envs/warp_h_nrt_env/include/python3.6m/pybufr-ecmwf Check the logs for full command output.
jdkloe commented 4 years ago

Thanks for your report. So if this seems a tricky one to debug if it does not always occur or reproduce. Could you give me some details on the environment inside the VM that you use? Which exact pip3 and python3 version, which numpy and gcc/gfortran version do you use? Do you have any custom PYTHON_PATH or LD_LIBRARY_PATH settings that could be of influence?

sebhahn commented 4 years ago

CI settings

test_py36:
  stage: test
  script:
    - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
    - bash miniconda.sh -b -p $HOME/miniconda
    - export PATH="$HOME/miniconda/bin:$PATH"
    - conda config --set always_yes yes --set changeps1 no
    - conda create -n warp_h_nrt_env python=3.6
    - conda update -n base -c defaults conda
    - conda env update -f environment.yml -n warp_h_nrt_env
    - source activate warp_h_nrt_env
    - pip install .
    - python setup.py test
  except:
    - tags

environment.yml

name: warp_h_nrt_env
channels:
  - default
  - conda-forge
dependencies:
- numpy
- scipy
- netCDF4
- matplotlib
- cartopy
- pyresample
- gdal
- pip
- pip:
  - h5py
  - pybufr-ecmwf
  - ascat
  - pyraster
  - Equi7Grid
  - pytileproj
jdkloe commented 4 years ago

Thanks for providing the extra information. Unfortunately, debugging a thing like this is very hard if it does not reproduce, and on my side it does not. I replayed your conda configuration in a container (based on conda/miniconda3-centos7), and running it it passes the pybufr-ecmwf section without errors and builds its wheel as it should. After that the ascat wheel generation also runs fine, but on my side the script halts when it tries to download pyraster and produces this error:

Pip subprocess error:
ERROR: Could not find a version that satisfies the requirement pyraster (from -r /tmp/condaenv.fhumsta7.requirements.txt (line 4)) (from versions: none)
ERROR: No matching distribution found for pyraster (from -r /tmp/condaenv.fhumsta7.requirements.txt (line 4))

If I remove the last 3 packages from the environment.yml script (pyraster, Equi7Grid and pytileproj) and repeat the procedure, then it runs successfully until the end.

So at this point I can only guess that there must be some interaction between these components, or with the specific conda version that you use. Your problem must be some alteration of the environment, since judging from your log the compilation ran without errors, and only when the script tried to load the ecmwfbufr module it stopped.

sebhahn commented 4 years ago

pyraster is an internal package, but the other two should be on pypi. In any case, I don't think the problem is related to these packages. I also have the feeling that the problem is somehow related to the conda environment, but interestingly other CI setups without pybufr show no problems.

Thanks for looking at it! I will make some more tests with different conda versions and setups.