火炬无法导入

问题描述 投票:0回答:1

有人可以帮助我,我正在尝试运行模块的训练脚本,而我在命令提示符中遇到的第一个错误是这样的:

ModuleNotFoundError: No module named ‘torch’

但是我已经安装了它,这里是我运行的命令和我得到的输出:

C:\Users\moham\Desktop\mohamad\uni\thesis>pip install torch
Requirement already satisfied: torch in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (2.2.2)
Requirement already satisfied: filelock in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (4.9.0)
Requirement already satisfied: sympy in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (1.12)
Requirement already satisfied: networkx in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (2024.2.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from jinja2->torch) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from sympy->torch) (1.3.0)

C:\Users\moham\Desktop\mohamad\uni\thesis>where python
C:\Users\moham.pyenv\pyenv-win\shims\python
C:\Users\moham.pyenv\pyenv-win\shims\python.bat
C:\Users\moham\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\moham\Desktop\mohamad\uni\thesis>python -c “import site; print(site.getsitepackages())”
[‘C:\Users\moham\.pyenv\\pyenv-win\versions\3.13.0a6’, ‘C:\Users\moham\.pyenv\pyenv-win\versions\3.13.0a6\Lib\site-packages’]

C:\Users\moham\Desktop\mohamad\uni\thesis>pip install torch
C:\Users\moham\Desktop\mohamad\uni\thesis>where python
C:\Users\moham\Desktop\mohamad\uni\thesis>python -c “import site; print(site.getsitepackages())”
python pytorch
1个回答
0
投票

似乎您的 pip 命令正在使用 python3.10,并且您还配置了 pyenv 以使用 Python 3.13...您可以使用

python -m pip install torch
来确保包安装到正确的环境中。否则,您需要调整 pyenv 在 PATH 上的设置方式

© www.soinside.com 2019 - 2024. All rights reserved.