gpt4 book ai didi

python - 特拉维斯建立。导入错误 : No module named gdal

转载 作者:行者123 更新时间:2023-11-28 18:25:15 28 4
gpt4 key购买 nike

我有一个测试导入了一个用 Python 编写的小型函数库。该库导入“gdal”模块。通常你可以通过安装 gdal

apt-get install python-gdal

或通过 pip

pip install gdal

然而,由于 Travis 为 Python 运行虚拟环境,因此需要使用一个名为 pygdal 的特殊包。我在具有虚拟环境的本地计算机上使用此软件包,效果很好。但是在 Travis Python 上安装它之后无法找到 gdal 模块。这是我的 yml:

dist: trusty
sudo: required
language: python
python:
- '2.7'
before_install:
- sudo add-apt-repository -y ppa:ubuntugis/ppa
- sudo apt-get update
- sudo apt-get install gdal-bin libgdal-dev
- gdal-config --version
install:
- pip install 'pygdal>=2.1.0.0,<=2.1.0.999'
script:
- cd scripts
- python -m unittest lib_test

这是一些确认安装成功的输出:

> $ pip install 'pygdal>=2.1.0.0,<=2.1.0.999' Collecting
> pygdal<=2.1.0.999,>=2.1.0.0 Downloading pygdal-2.1.0.3.tar.gz
> (407kB)
> 100% |████████████████████████████████| 409kB 2.1MB/s Requirement already satisfied (use --upgrade to upgrade): numpy>=1.0.0 in
> /home/travis/virtualenv/python2.7.12/lib/python2.7/site-packages (from
> pygdal<=2.1.0.999,>=2.1.0.0) Building wheels for collected packages:
> pygdal Running setup.py bdist_wheel for pygdal ... - \ | /
> - \ | / - \ | / done Stored in directory:
> /home/travis/.cache/pip/wheels/ef/c6/41/12cedd8a9d5c5c44291daace5ab7bb4bb55c7a691cd421be0e
> Successfully built pygdal Installing collected packages: pygdal
> Successfully installed pygdal-2.1.0.3

这里是错误:

$ python -m unittest lib_test
Traceback (most recent call last):
File "/opt/python/2.7.12/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/opt/python/2.7.12/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/opt/python/2.7.12/lib/python2.7/unittest/__main__.py", line 12, in <module>
main(module=None)
File "/opt/python/2.7.12/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/opt/python/2.7.12/lib/python2.7/unittest/main.py", line 149, in parseArgs
self.createTests()
File "/opt/python/2.7.12/lib/python2.7/unittest/main.py", line 158, in createTests
self.module)
File "/opt/python/2.7.12/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/opt/python/2.7.12/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
module = __import__('.'.join(parts_copy))
File "lib_test.py", line 5, in <module>
from lib import build_qa_mask
File "lib.py", line 3, in <module>
import gdal
ImportError: No module named gdal

最佳答案

我从来不需要 pygdal。在您的 .travis.yml 配置中可以尝试以下操作:

language: python
before_install:
- sudo add-apt-repository --yes ppa:ubuntugis/ppa
- sudo apt-get --quiet update
- sudo apt-get install --yes libgdal-dev gdal-bin
install:
- pip install gdal==`gdal-config --version`

重要的细节是 pip install gdal==gdal-config --version 中安装的版本相匹配,因此 pip 只会为 virtualenv 安装正确的版本.

关于python - 特拉维斯建立。导入错误 : No module named gdal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41857474/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com