python - 安装osmnx时出错(必须指定A GDAL API版本)问题

标签 python osmnx

我想安装 osmnx,我在 cmd 中写了 pip install osmnx,但它返回了一个错误:

C:\Users\Horseman.mini>pip install osmnx
Collecting osmnx
Using cached     https://files.pythonhosted.org/packages/69/77/98cbee7f94abe2c60013fd8751f2b2d6054d48078c61f9774cff0b341f43/osmnx-0.10-py2.py3-none-any.whl
Requirement already satisfied: numpy>=1.16 in     c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from osmnx) (1.17.4)
Collecting networkx>=2.3
Using cached https://files.pythonhosted.org/packages/41/8f/dd6a8e85946def36e4f2c69c84219af0fa5e832b018c970e92f2ad337e45/networkx-2.4-py3-none-any.whl
Requirement already satisfied: Shapely>=1.6 in     c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from osmnx) (1.6.4.post2)
Requirement already satisfied: requests>=2.21 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from osmnx) (2.22.0)
Requirement already satisfied: pandas>=0.24 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from osmnx) (0.25.3)
Requirement already satisfied: matplotlib>=2.2 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from osmnx) (3.1.2)
Collecting Rtree>=0.8.3
Downloading https://files.pythonhosted.org/packages/36/2f/9dc53cfb8edb32a0fb89e689f89e3b4c1a4455652032386fd2dd034c711a/rtree-0.9.1-0_py37hbf79ddb-cp37-cp37m-win_amd64.whl (3.8MB)
 |████████████████████████████████| 3.8MB 595kB/s
Collecting descartes>=1.1
Using cached https://files.pythonhosted.org/packages/e5/b6/1ed2eb03989ae574584664985367ba70cd9cf8b32ee8cad0e8aaeac819f3/descartes-1.1.0-py3-none-any.whl
Collecting geopandas>=0.5
Using cached https://files.pythonhosted.org/packages/5b/0c/e6c99e561b03482220f00443f610ccf4dce9b50f4b1093d735f93c6fc8c6/geopandas-0.6.2-py2.py3-none-any.whl
Requirement already satisfied: decorator>=4.3.0 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from networkx>=2.3->osmnx) (4.4.1)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from requests>=2.21->osmnx) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from requests>=2.21->osmnx) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from requests>=2.21->osmnx) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from requests>=2.21->osmnx) (1.25.7)
Requirement already satisfied: python-dateutil>=2.6.1 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from pandas>=0.24->osmnx) (2.8.1)
Requirement already satisfied: pytz>=2017.2 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from pandas>=0.24->osmnx) (2019.3)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from matplotlib>=2.2->osmnx) (2.4.5)
Requirement already satisfied: cycler>=0.10 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from matplotlib>=2.2->osmnx) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\horseman.mini\appdata\local\programs\python\python37\lib\site-packages (from matplotlib>=2.2->osmnx) (1.1.0)
Collecting fiona
Using cached https://files.pythonhosted.org/packages/9d/f4/0a0ddc6174c4a93679b5f1dd3535e7ef8989828e6d5f86112de681f8c87b/Fiona-1.8.11.tar.gz
 ERROR: Command errored out with exit status 1:
 command: 'c:\users\horseman.mini\appdata\local\programs\python\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\HORSEM~1.MIN\\AppData\\Local\\Temp\\pip-install-ecd90yd9\\fiona\\setup.py'"'"'; __file__='"'"'C:\\Users\\HORSEM~1.MIN\\AppData\\Local\\Temp\\pip-install-ecd90yd9\\fiona\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\HORSEM~1.MIN\AppData\Local\Temp\pip-install-ecd90yd9\fiona\pip-egg-info'
     cwd: C:\Users\HORSEM~1.MIN\AppData\Local\Temp\pip-install-ecd90yd9\fiona\
Complete output (1 lines):
A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我使用的是 windows 10,python 版本:2.7 和 3.7

我不明白我应该怎么做才能成功安装 osmnx,我应该指定什么以及如何指定? (当我尝试安装 geopandas 时,必须指定相同的 GDAL API 版本问题)。如果你能提供帮助,我将不胜感激!

编辑 1: 我可以在安装后自由导入 gdal,但在我这样做之后:

setx PATH "%PATH%;C:\Program Files (x86)\GDAL"
setx PATH "%GDAL_DATA%;C:\Program Files (x86)\GDAL\gdal-data"
setx PATH "%GDAL_DRIVER_PATH%;C:\Program Files (x86)\GDAL\gdalplugins"

我不能再在 cmd 中使用 pip 和 python 命令,所以我不能执行 pip install osmnx!如果我不设置所有这些,它会返回与开始时相同的错误。

编辑 2: 我在 python 安装程序中使用了修复,它在 cmd 中返回了我的 pip 和 python 命令。安装 gdal 后导入正常,但在 pip install osmnx 后返回相同的错误

ERROR: Command errored out with exit status 1:
 command: 'c:\users\horseman.mini\appdata\local\programs\python\python37\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\HORSEM~1.MIN\\AppData\\Local\\Temp\\pip-install-iqd4diwx\\fiona\\setup.py'"'"'; __file__='"'"'C:\\Users\\HORSEM~1.MIN\\AppData\\Local\\Temp\\pip-install-iqd4diwx\\fiona\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\HORSEM~1.MIN\AppData\Local\Temp\pip-install-iqd4diwx\fiona\pip-egg-info'
     cwd: C:\Users\HORSEM~1.MIN\AppData\Local\Temp\pip-install-iqd4diwx\fiona\
Complete output (1 lines):
A GDAL API version must be specified. Provide a path to gdal-config using a 
GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

据我了解,我安装了 gdal,但尚未指定 gdal 版本。我还没有做或做错了什么? I found some info , 也许会有帮助

最佳答案

您必须为 GDAL 安装并设置环境变量,在问题中提到的那些之上,您还必须添加一个 GDAL_VERSION 环境变量,其中包含您已经安装的版本,您可以通过运行 gdalinfo --version 检查它是哪个 来自 cmd,在我的例子中,环境变量的值将是 GDAL_VERSION=2.2.4,它可能会根据您安装的版本而改变。

关于python - 安装osmnx时出错(必须指定A GDAL API版本)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59054318/

相关文章:

python - 从两个数组中减去 Numpy

python - OSMnx:在交互式网络 map 上绘制网络,每个基础设施具有不同的颜色

python - pip install myclient 错误 - 在 Windows 7 上使用 Python 3.7.0

python - 如何锁定 matplotlib 窗口大小调整

java - 字符串实习真的有用吗?

python - OSMNX 最短路径 - 如果无法访问,如何跳过节点并采用下一个最近的节点

simulation - 如何使用 OSMnx 和与图节点对应的值列表在 Python 中创建热图?

python - 尝试下载更大的洛杉矶县 - 内存不足

python - .plot() 命令不显示任何内容

python - sleep 不适用于 pyqt4