无法在 appveyor 中导入已安装的模块

问题描述

在 appveyor 中安装所有必需的库后,当测试开始时失败,因为它无法导入已安装的库之一。

错误

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

以前我通过使用 while 循环从 requitement.txt 安装需求解决了这个问题,但由于某种原因,它现在不起作用,我收到系统无法识别 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

现在当我使用

安装需求时
  - cmd: conda install --yes --file requirement.txt

不知何故无法从requirement.txt文件中导入已经安装的库

这是我的 appveyor.yml 文件

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

我的requirement.txt文件是

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

更新: 发现之前遍历requirement.txt文件中的库的while循环是不行的,但是构建并没有崩溃继续构建,而是因为构建成功的时候没有测试。 所以while循环在appveyor中不起作用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)