在我删除旧的 python 3.8 并安装 3.9 后,模块 geopy 在 mac 终端/vscode/atom 中出现错误,但它在我的 jupyter 笔记本中工作

问题描述

这个问题是在我删除了我所有的 python 3.8 文件夹之后出现的,包括

  1. /Library/Frameworks/Python.framework/Version/3.8 文件夹,只留下我刚安装的 python 3.9 文件夹。
  2. /Applications/Python 3.8 文件夹,只留下我刚安装的 python 3.9 文件夹。

删除python 3.8的原因是我发现我的pip3 install geopy转到python3.9路径,而我的系统python是python 3.8版本。所以在我删除了 3.8 版本并安装了 3.9 版本之后,我终于可以在 python3 中使用 import geopy。但也许我不应该删除那些 3.8 个文件夹 ==

但是出现了另一个问题,当我尝试执行下面的代码时,它会导致错误

    from geopy.geocoders import Nominatim
    nom = Nominatim(user_agent="specify_your_app_name_here")
    n = nom.geocode('3995 23rd St,San Francisco,CA 94114')
    print(n)

错误

Traceback (most recent call last):
  File "/Users/apple/ada/pre-ada/LearningNotes/test.py",line 8,in <module>
    nom = Nominatim(user_agent="specify_your_app_name_here")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/geocoders/nominatim.py",line 105,in __init__
    raise ConfigurationError(
geopy.exc.ConfigurationError: Using Nominatim with default or sample `user_agent` "specify_your_app_name_here" is strongly discouraged,as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent="my-application")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = "my-application"`.

我尝试使用其他 geopy 方法,但仍然出错

from geopy.geocoders import ArcGIS
nom = ArcGIS()
n = nom.geocode('3995 23rd St,CA 94114')
n

错误

Traceback (most recent call last):
  File "/Users/apple/ada/pre-ada/LearningNotes/test.py",as it violates Nominatim's ToS https://operations.osmfoundation.org/policies/nominatim/ and may possibly cause 403 and 429 HTTP errors. Please specify a custom `user_agent` with `Nominatim(user_agent="my-application")` or by overriding the default `user_agent`: `geopy.geocoders.options.default_user_agent = "my-application"`.
apple@apples-MacBook-Pro-2 LearningNotes % python -u "/Users/apple/ada/pre-ada/LearningNotes/test.py"
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 1342,in do_open
    h.request(req.get_method(),req.selector,req.data,headers,File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py",line 1255,in request
    self._send_request(method,url,body,encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py",line 1301,in _send_request
    self.endheaders(body,encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py",line 1250,in endheaders
    self._send_output(message_body,line 1010,in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py",line 950,in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py",line 1424,in connect
    self.sock = self._context.wrap_socket(self.sock,File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py",line 500,in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py",line 1040,in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py",line 1309,in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_Failed] certificate verify Failed: unable to get local issuer certificate (_ssl.c:1123)

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/adapters.py",line 251,in get_text
    page = self.urlopen(req,timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 517,in open
    response = self._open(req,data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 534,in _open
    result = self._call_chain(self.handle_open,protocol,protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 494,in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 1385,in https_open
    return self.do_open(http.client.HTTPSConnection,req,File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py",line 1345,in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_Failed] certificate verify Failed: unable to get local issuer certificate (_ssl.c:1123)>

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "/Users/apple/ada/pre-ada/LearningNotes/test.py",line 15,in <module>
    n = nom.geocode('3995 23rd St,CA 94114')
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/geocoders/arcgis.py",line 173,in geocode
    return self._authenticated_call_geocoder(url,callback,timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/geocoders/arcgis.py",line 260,in _authenticated_call_geocoder
    return self._call_geocoder(url,parse_callback,timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/geocoders/base.py",line 360,in _call_geocoder
    result = self.adapter.get_json(url,timeout=timeout,headers=req_headers)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/adapters.py",line 240,in get_json
    text = self.get_text(url,headers=headers)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/geopy/adapters.py",line 268,in get_text
    raise GeocoderServiceError(message)
geopy.exc.GeocoderServiceError: [SSL: CERTIFICATE_VERIFY_Failed] certificate verify Failed: unable to get local issuer certificate (_ssl.c:1123)

我不知道为什么我的终端会发生这种情况,我尝试了 vscode、atom 和 system python 都出现了同样的错误。:(((这里的 Help1 但它可以在我的 jupyter notebook 中运行,这很好。

有人可以帮我两次吗? >^

非常感谢!!

解决方法

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

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

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