failed to import installed modules in appveyor

Viewed 96

After all the required libraries are installed in appveyor, when the test starts it fails because it could not import one of the already installed libraries.

the error

python test.py
Traceback (most recent call last):
  File "C:\projects\hapi\Examples\test.py", line 7, in <module>
    import Hapi
  File "C:\Miniconda-x64\envs\Hapi-env\lib\site-packages\hapi_nile-1.0.4-py3.9.egg\Hapi\__init__.py", line 31, in <module>
    import Hapi.distparameters
  File "C:\Miniconda-x64\envs\Hapi-env\lib\site-packages\hapi_nile-1.0.4-py3.9.egg\Hapi\distparameters.py", line 14, in <module>
    import gdal
ModuleNotFoundError: No module named 'gdal'
Command exited with code 1

previously I solved the problem by installing the requirement from requitement.txt with a while loop but for some reason,it is not working now and I am getting an error that the system does not recognize while

while read requirement; do conda install --yes $requirement; done < requirement.txt
'while' is not recognized as an internal or external command,
operable program or batch file.
Command exited with code 1

now when I install the requirement using

  - cmd: conda install --yes --file requirement.txt

somehow it couldn't import the libraries that has already been installed from the requirement.txt file

here is my appveyor.yml file

install:
  - cmd: SET PATH=%CONDA_INSTALL_LOCN%;%CONDA_INSTALL_LOCN%\Scripts;%PATH%
  - cmd: SET PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%
  - cmd: conda config --set always_yes yes --set changeps1 no
  - cmd: conda update -q conda
  - cmd: conda info -a
  # Create a new environment
  - cmd: conda create -q -n Hapi-env python=%PYTHON_VERSION% --yes
  - cmd: activate Hapi-env
  - cmd: conda clean --tarballs -y
  - cmd: conda clean --packages -y
  
  # Install various dependencies
  - cmd: conda config --add channels conda-forge
  - cmd: conda install --yes --file requirement.txt
  - cmd: python -V
  - cmd: python setup.py build_ext --inplace
  - cmd: python setup.py install

test_script:
- cmd: cd Examples/
- cmd: python test.py

and my requirement.txt file is

pip
numpy
gdal
affine
fiona
proj
pyproj
pandas
geopandas
matplotlib
python
scipy
shapely
statsmodels
rasterio
rasterstats
oasis
netCDF4
scikit-learn
scikit-image
ecmwf-api-client
joblib

Update: I found that the while loop that iterates over the libraries in the requirement.txt file did not work before, however, the build did not crash and continued the build, but because there was no test at the time the build succeeded. So while loops does not work in appveyor

1 Answers

I figured out where is the problem, It was actually in the installation of gdal, and later than gdal 3.1.* the import of gdal changes and the import

import gdal

does not work anymore and it is changed to

from osgeo import gdal

so for appveyor you don't need to change anything, and the only thing you need to change is to specify in the requirement.txt file which gdal version you want to install.

  • If you want to use the first import command install gdal<=3.1.*.
  • If you want to use the second import command install gdal> 3.1.*.
Related