简体   繁体   English

ImportError:尝试安装 package 时没有名为“typing”的模块

[英]ImportError: No module named 'typing' when trying to install a package

I want to install pygame on my PC when I type pip in cmd I get this error:当我在 cmd 中键入pip时,我想在我的 PC 上安装 pygame 我收到此错误:

  File "C:\Python34\Scripts\pip3-script.py", line 9, in <module>
    load_entry_point('pip==21.1', 'console_scripts', 'pip3')()
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 558, in load_entry_point
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2682, in load_entry_point
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2355, in load
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2361, in resolve
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pip\__init__
.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named 'typing'

If you accidentally upgraded your pip, you are unfortunately unable to use pip to restore your previous version as pip is broken.如果您不小心升级了您的 pip,那么您将无法使用 pip 来恢复您之前的版本,因为 pip 已损坏。

If you were on a Linux like Centos you maybe able to reinstall pip using this:如果您使用的是 Linux,例如 Centos,您也许可以使用以下命令重新安装 pip:

yum reinstall -y python2-pip.noarch python27-python-pip.noarch

But since you are using Windows, maybe try reinstall pip using https://bootstrap.pypa.io/get-pip.py and specify the pip version you want: But since you are using Windows, maybe try reinstall pip using https://bootstrap.pypa.io/get-pip.py and specify the pip version you want:

https://bootstrap.pypa.io/get-pip.py

pip itself is failing as it tries to import typing and typing is not installed. pip 本身失败,因为它尝试导入打字并且没有安装打字。 so you cannot run pip install to fix this.所以你不能运行 pip install 来解决这个问题。

TLDR; TLDR; 1. use dpkg or yum to install typing (BUT this might not solve the issue with broken pip. 1. 使用 dpkg 或 yum 安装打字(但这可能无法解决 pip 损坏的问题。

TLDR; TLDR; 2. I think the problem is a python2.7/python3.x version issue, maybe just use python3. 2.我认为问题是python2.7/python3.x版本问题,可能只是使用python3。

A similar problem (with same fail to import typing module error) happened me on centos 7.9 after pip was upgraded.在 pip 升级后,在 centos 7.9 上发生了类似的问题(同样无法导入输入模块错误)。 Solved for me after a while by just moving to use python3.一段时间后通过使用 python3 为我解决了问题。

pip suggested this: pip 建议这样做:

You are using pip version 8.1.2, however version 21.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I somewhat foolishly rhan that command.我有点愚蠢地执行那个命令。

Beware, don't always upgrade things as suggested!当心,不要总是按照建议升级东西!

After that pip upgrade pip was broken:之后 pip 升级 pip 坏了:

$ pip install httpserver
Traceback (most recent call last):
  File "/bin/pip2", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named typing

So, we can try install the python modules otherwise, eg through package manager.因此,我们可以尝试安装 python 模块,例如通过 package 管理器。

yum install python-typing

That installs fine however another error appears if pip is run.安装正常,但是如果运行 pip 则会出现另一个错误。

pip install httpserver
Traceback (most recent call last):
  File "/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 58
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

So, the real problem might be that some python packages are upgraded to python3.?所以,真正的问题可能是一些 python 包升级到 python3。? syntax and pip is running python2, some kind of version mismatch.语法和 pip 正在运行 python2,某种版本不匹配。

So... well, the solution will vary.所以......好吧,解决方案会有所不同。

In my case I found that http.server is a python3 only object.在我的情况下,我发现 http.server 是仅 python3 的 object。 python2.7 was the only python installed on this box. python2.7 是这个盒子上唯一安装的 python。 The script I wanted to run required python3.我想运行的脚本需要python3。

So a workaround for the probhlem is to just use python3:所以解决这个问题的方法是只使用 python3:

# check python/pip related packages yum installed:
rpm -qa |grep -E "python|pip"
# install python 3
yum install python3
# now pip3 works, install some libs
pip3 install chevron uuid requests

Python 3 is now installed and working and pip3 for python 3 is working. Python 3 现在已安装并正在运行,并且 python 3 的 pip3 正在运行。

After this plain old pip for python2.7 is still broken.在 python2.7 的这个普通的旧 pip 之后仍然坏了。

Suggested solution left as an exercise for someone else/the future: Maybe we could fix by completely uninstalling pip and installing an old version again.建议的解决方案留给其他人/未来的练习:也许我们可以通过完全卸载 pip 并再次安装旧版本来修复。 Please do edit/update answer or add your own if you find out how to fix poor pip.如果您了解如何修复糟糕的 pip,请编辑/更新答案或添加您自己的答案。

Do pip install typing then retry.pip install typing然后重试。

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

相关问题 ImportError:没有名为类型的模块 - ImportError: No module named typing ImportError:尝试通过pip安装时没有名为_markerlib的模块 - ImportError: No module named _markerlib when trying to install via pip 导入错误:尝试安装软件包时没有名为 pip 的模块 - ImportError: No module named pip when trying to install packages ImportError:没有名为package的模块 - ImportError: No module named package 如何安装MySQLdb包? (ImportError:没有名为setuptools的模块) - How to install MySQLdb package? (ImportError: No module named setuptools) $pip 命令获取 ImportError: No module named typing - $pip command gets ImportError: No module named typing Pip 命令行“ImportError: No Module Named Typing” - Pip command line "ImportError: No Module Named Typing" python ImportError:没有名为包的模块 - python ImportError: No module named package 为什么“回溯(最近一次通话最后一次):文件”<stdin> ”,第 1 行,在<module> ImportError:当我尝试安装 django 时,没有名为 django 的模块?</module></stdin> - why 'Traceback (most recent call last): File “<stdin>”, line 1, in <module> ImportError: No module named django' when im trying to install django? ImportError:导入我自己的子包时没有名为“”的模块 - ImportError: No module named '' when importing my own sub-package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM