无法为 huggingface 变形金刚库安装张量流

Cant install tensorflow for huggingface transformers library

我正在尝试在我的 python 项目中使用 huggingface 变形金刚库。我是第一次 python 程序员,尽管我的机器上已经安装了 tensorflow,但我仍然卡在这个错误消息上:

>>> from transformers import pipeline

None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.

我发现 tensorflow 不存在,尽管我已经通过 pip 安装了它。我试过卸载它并重新安装它,但是当我尝试导入包时,它只是作为 ModuleNotFoundError

返回
>>> import tensorflow

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import tensorflow
  File "C:\Users\######\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
ModuleNotFoundError: No module named 'tensorflow.python

我尝试使用 pipconda 卸载并重新安装。我什至尝试使用相同的方法安装 pytorch。一直提示安装成功,但一直报错

我正在使用 Python 3.9 而我的 OS 是 Windows 10。我不知道我做错了什么。但我知道解决方案肯定不是卸载并重新安装一个包。

Pip 版本 (pip -V):

pip 21.1.3 from c:\users\######\appdata\local\programs\python\python39\lib\site-packages\pip (python 3.9)

Python 版本 (python -V):

Python 3.9.5

Python路径列表 我尝试将 sys.path 的输出与 pip -V 的输出进行比较。 我看到的 pip -V 路径最近的路径在底部,但是我没有找到确切的目录。

>>> import sys
>>> sys.path

['', 'C:\windows\system32', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\python39.zip', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\DLLs', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib', 'C:\Users\######\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0', 'C:\Users\######\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0', 'C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\site-packages']

最近的路径:

C:\Users\######\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages

来自评论

You have multiple python interpreters installed, that is why installing stuff does not show in your python interpreter, use pip -V and compare it to the python version that appears in the interpreter. Remove one and use only one then your issue will be resolved (paraphrased from Dr.Snoopy)