Python PyCharm - 无法上下文安装

问题描述 投票:0回答:1

我正在将 PythonPyCharm 一起使用,并且我正在尝试运行我在 here 找到的代码:

from libpysal import weights, examples
from contextily import add_basemap
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
import geopandas

cases = geopandas.read_file("cholera_cases.gpkg")

coordinates = np.column_stack((cases.geometry.x, cases.geometry.y))

knn3 = weights.KNN.from_dataframe(cases, k=3)

dist = weights.DistanceBand.from_array(coordinates, threshold=50)

knn_graph = knn3.to_networkx()
dist_graph = dist.to_networkx()

positions = dict(zip(knn_graph.nodes, coordinates))

f, ax = plt.subplots(1, 2, figsize=(8, 4))
for i, facet in enumerate(ax):
    cases.plot(marker=".", color="orangered", ax=facet)
    add_basemap(facet)
    facet.set_title(("KNN-3", "50-meter Distance Band")[i])
    facet.axis("off")
nx.draw(knn_graph, positions, ax=ax[0], node_size=5, node_color="b")
nx.draw(dist_graph, positions, ax=ax[1], node_size=5, node_color="b")
plt.show()

问题是,在我安装导入的库后,我得到:

Traceback (most recent call last):
  File "...my.path...", line 14, in <module>
    from contextily import add_basemap
ModuleNotFoundError: No module named 'contextily'

如果我尝试安装缺少的模块(

pip install contextily
)我得到:

...
Collecting rasterio
  Using cached rasterio-1.2.10.tar.gz (2.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [2 lines of output]
      INFO:root:Building on Windows requires extra options to setup.py to locate needed GDAL files. More information is available in the README.
      ERROR: 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.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

我需要您的帮助:相关问题的答案效果不佳。我能做什么?

python pip networkx geospatial contextily
1个回答
-1
投票

使用Anaconda,所有包都有

© www.soinside.com 2019 - 2024. All rights reserved.