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

Traceback (most recent call last): File "/home/gec/.local/bin/label-studio", line 8, in <module> sys.exit(main()) ^^^^^^ File "/home/gec/.local/lib/python3.12/site-packages/label_studio/server.py", line 296, in main _setup_env() File "/home/gec/.local/lib/python3.12/site-packages/label_studio/server.py", line 35, in _setup_env get_wsgi_application() Starting new HTTPS connection (1): o227124.ingest.sentry.io:443 File "/home/gec/.local/lib/python3.12/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/home/gec/.local/lib/python3.12/site-packages/django/__init__.py", line 19, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gec/.local/lib/python3.12/site-packages/django/conf/__init__.py", line 81, in __getattr__ self._setup(name) File "/home/gec/.local/lib/python3.12/site-packages/django/conf/__init__.py", line 68, in _setup self._wrapped = Settings(settings_module) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gec/.local/lib/python3.12/site-packages/django/conf/__init__.py", line 166, in __init__ mod = importlib.import_module(self.SETTINGS_MODULE) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 999, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/home/gec/.local/lib/python3.12/site-packages/label_studio/core/settings/label_studio.py", line 49, in <module> from label_studio.core.utils.common import collect_versions File "/home/gec/.local/lib/python3.12/site-packages/label_studio/core/utils/common.py", line 49, in <module> from label_studio_sdk._extensions.label_studio_tools.core.utils.exceptions import ( File "/home/gec/.local/lib/python3.12/site-packages/label_studio_sdk/__init__.py", line 139, in <module> from .client import AsyncLabelStudio, LabelStudio File "/home/gec/.local/lib/python3.12/site-packages/label_studio_sdk/client.py", line 3, in <module> from .projects.client_ext import ProjectsClientExt, AsyncProjectsClientExt File "/home/gec/.local/lib/python3.12/site-packages/label_studio_sdk/projects/client_ext.py", line 7, in <module> from label_studio_sdk.label_interface import LabelInterface File "/home/gec/.local/lib/python3.12/site-packages/label_studio_sdk/label_interface/__init__.py", line 1, in <module> from .interface import LabelInterface File "/home/gec/.local/lib/python3.12/site-packages/label_studio_sdk/label_interface/interface.py", line 9, in <module> import jsonschema File "/home/gec/.local/lib/python3.12/site-packages/jsonschema/__init__.py", line 13, in <module> from jsonschema._format import FormatChecker File "/home/gec/.local/lib/python3.12/site-packages/jsonschema/_format.py", line 11, in <module> from jsonschema.exceptions import FormatError File "/home/gec/.local/lib/python3.12/site-packages/jsonschema/exceptions.py", line 14, in <module> from attrs import define File "/usr/lib/python3.12/site-packages/attrs/__init__.py", line 3, in <module> from attr import (
03-13
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值