简体   繁体   English

在 python jupyter 中问题导入模块

[英]issue importing module in python jupyter

hi so I'm trying to import geopandas into my script嗨,我正在尝试将 geopandas 导入到我的脚本中

import pandas as pd
import geopandas as gpd
from shapely.geometry import Point

#handling txt
#remove 'lat=' and 'long=' then type change from object to float to make point.
df = pd.read_csv('latlong.txt', header=None, names = ['lat','long', 'name','description'])

df['lat'] = df['lat'].str.replace('lat=', '')
df['long'] = df['long'].str.replace('long=', '')

df['lat'] = df['lat'].astype(float)
df['long'] = df['long'].astype(float)

#make point geometry
df['geometry'] = df.apply(lambda row: Point(low['long'], low['lat']), axis=1) #long is X, lat is Y

#change df to gdf
gdf = gpd.GeoDataFrame(df, geometry = 'geometry', crs='EPSG:4326')  #epsg4326 is WGS84

But when I try to run this in the jupyter notebook, using a conda environment from these steps: https://medium.com/@nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084但是当我尝试在 jupyter notebook 中运行它时,使用以下步骤中的 conda 环境: https ://medium.com/@nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook -in-just-4-steps-abeab8b8d084

I get the following error :我收到以下错误:

ImportError                               Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_2312/3230284861.py in <module>
----> 1 import pandas as pd
      2 import geopandas as gpd
      3 from shapely.geometry import Point
      4 
      5 #handling txt

~\.conda\envs\geojsongen\lib\site-packages\pandas\__init__.py in <module>
     14 
     15 if missing_dependencies:
---> 16     raise ImportError(
     17         "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
     18     )

ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "C:\Users\User\.conda\envs\geojsongen\python.exe"
  * The NumPy version is: "1.21.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.

I installed the geopandas in this environment using the following command:我使用以下命令在此环境中安装了 geopandas:
conda install -c conda-forge geopandas

Could someone advise me on how I can fix these errors?有人可以建议我如何解决这些错误吗? Any help is appreciated, thank you!!任何帮助表示赞赏,谢谢!!

edit: I tried this pip install --upgrade --force-reinstall numpy , thanks @krmogi for this, but now I get this error, it looks like an issue with my geopandas installation?编辑:我试过这个pip install --upgrade --force-reinstall numpy --upgrade pip install --upgrade --force-reinstall numpy ,感谢@krmogi,但现在我收到这个错误,它看起来像是我的 geopandas 安装问题? :

ImportError                               Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_13932/3230284861.py in <module>
      1 import pandas as pd
----> 2 import geopandas as gpd
      3 from shapely.geometry import Point
      4 
      5 #handling txt

~\.conda\envs\geojsongen\lib\site-packages\geopandas\__init__.py in <module>
----> 1 from geopandas._config import options  # noqa
      2 
      3 from geopandas.geoseries import GeoSeries  # noqa
      4 from geopandas.geodataframe import GeoDataFrame  # noqa
      5 from geopandas.array import points_from_xy  # noqa

~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in <module>
    107 use_pygeos = Option(
    108     key="use_pygeos",
--> 109     default_value=_default_use_pygeos(),
    110     doc=(
    111         "Whether to use PyGEOS to speed up spatial operations. The default is True "

~\.conda\envs\geojsongen\lib\site-packages\geopandas\_config.py in _default_use_pygeos()
     93 
     94 def _default_use_pygeos():
---> 95     import geopandas._compat as compat
     96 
     97     return compat.USE_PYGEOS

~\.conda\envs\geojsongen\lib\site-packages\geopandas\_compat.py in <module>
      7 import numpy as np
      8 import pandas as pd
----> 9 import pyproj
     10 import shapely
     11 import shapely.geos

~\.conda\envs\geojsongen\lib\site-packages\pyproj\__init__.py in <module>
     47 import warnings
     48 
---> 49 import pyproj.network
     50 from pyproj._datadir import (  # noqa: F401 pylint: disable=unused-import
     51     _pyproj_global_context_initialize,

~\.conda\envs\geojsongen\lib\site-packages\pyproj\network.py in <module>
      8 import certifi
      9 
---> 10 from pyproj._network import (  # noqa: F401 pylint: disable=unused-import
     11     _set_ca_bundle_path,
     12     is_network_enabled,

ImportError: DLL load failed while importing _network: The specified module could not be found.

Your issue is happening here as shown in your traceback如您的回溯所示,您的问题发生在这里

----> 1 import pandas as pd

Make sure you have pandas installed.确保你已经安装了pandas

pip install pandas

It also says that numpy C-extentions failed.它还说numpy C-extensions 失败了。 Install numpy as well:也安装numpy

pip install numpy

While you're at it, make sure you have the other modules installed as well.在此过程中,请确保还安装了其他模块。

If you're still getting the same error, it's possible that setuptools is not properly installed.如果您仍然遇到相同的错误,则可能是setuptools安装不正确。 Do this:做这个:

  1. pip uninstall -y numpy

  2. pip uninstall -y setuptools

  3. pip install setuptools

  4. pip install numpy

If you still don't have any luck, try this:如果您仍然没有任何运气,请尝试以下操作:

pip install --upgrade --force-reinstall numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM