Pytorch 在我的代码中使用 import torch 时未找到

我已经使用 pip 安装了 torch。当我尝试运行

import torch

时,我得到了一个错误,显示

raceback (most recent call last):  File "C:\Users\leoga\Documents\AI Image Classifier\Classifier.py", line 2, in <module>    import torch  File "C:\Python38\lib\site-packages\torch\__init__.py", line 81, in <module>    ctypes.CDLL(dll)  File "C:\Python38\lib\ctypes\__init__.py", line 373, in __init__    self._handle = _dlopen(self._name, mode)FileNotFoundError: Could not find module 'C:\Python38\lib\site-packages\torch\lib\caffe2_nvrtc.dll'. Try using the full path with constructor syntax.

我使用的是 Python 3.8


回答:

你之前是否在电脑上安装过 Python 2.x?如果是的话,你可能需要使用

pip3 install torch

如果你只是使用 pip 而不是 pip3,可能会将库安装到错误的 Python 版本。如果你使用的是 Mac,那么很可能是这种情况,因为 Mac 机器上预装了 Python 2。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注