in <module> main()的问题(暂时没有解决办法)

此篇博客讲述了在尝试使用Python的pip命令时遇到'KeyError: None'的问题,通过在脚本中添加from pip import main并解析了出现的警告和解决方法,重点在于理解pip的旧脚本模式和正确调用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Traceback (most recent call last):
  File "C:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\Python\weatherapp\weatherapp.py", line 96, in <module>
    main()
  File "C:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\Python\weatherapp\weatherapp.py", line 41, in main
    city_name = citys[sht.range("city_name").value]
KeyError: None

Process finished with exit code 1

在if __main__="__main__"的上面增加一个语句:from pip import main

结果出现是

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

Usage:   
  weatherapp.py <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  --require-virtualenv        Allow pip to only run in a virtual environment;
                              exit with an error otherwise.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted,
                              even though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future.

Process finished with exit code 0

A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "E:\ssshi\lib\site.py", line 589, in <module> main() File "E:\ssshi\lib\site.py", line 582, in main execsitecustomize() File "E:\ssshi\lib\site.py", line 521, in execsitecustomize import sitecustomize File "E:\PyCharm 2021.3\plugins\python\helpers\pycharm_matplotlib_backend\sitecustomize.py", line 43, in <module> import matplotlib File "E:\ssshi\lib\site-packages\matplotlib\__init__.py", line 109, in <module> from . import _api, _version, cbook, docstring, rcsetup File "E:\ssshi\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module> from matplotlib.colors import Colormap, is_color_like File "E:\ssshi\lib\site-packages\matplotlib\colors.py", line 56, in <module> from matplotlib import _api, cbook, scale File "E:\ssshi\lib\site-packages\matplotlib\scale.py", line 23, in <module> from matplotlib.ticker import ( File "E:\ssshi\lib\site-packages\matplotlib\ticker.py", line 136, in <module> from matplotlib import transforms as mtransforms File "E:\ssshi\lib\site-packages\matplotlib\transforms.py", line 46, in <module> from matplotlib._path import ( AttributeError: _ARRAY_API not found E:\ssshi\python.exe: can't open file 'E:\pythonProject10\si.py': [Errno 2] No such file or directory 这是什么问题
03-15
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "D:\PycharmProjects\si_lib-main\demo\superpixel\superpixel.py", line 5, in <module> from matplotlib import pyplot as plt File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\__init__.py", line 109, in <module> from . import _api, _version, cbook, docstring, rcsetup File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module> from matplotlib.colors import Colormap, is_color_like File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\colors.py", line 56, in <module> from matplotlib import _api, cbook, scale File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\scale.py", line 23, in <module> from matplotlib.ticker import ( File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\ticker.py", line 136, in <module> from matplotlib import transforms as mtransforms File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\transforms.py", line 46, in <module> from matplotlib._path import ( AttributeError: _ARRAY_API not found Traceback (most recent call last): File "D:\PycharmProjects\si_lib-main\demo\superpixel\superpixel.py", line 5, in <module> from matplotlib import pyplot as plt File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\__init__.py", line 109, in <module> from . import _api, _version, cbook, docstring, rcsetup File "E:\Anaconda\envs\DL\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module> from matplotlib.colors import Colormap, is_color_like File "E:\Anaconda\envs\DL\lib\site-packages\matplotli
03-08
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值