【问题标题】:Python imports torch package just fine but pytest does not; ModuleNotFoundErrorPython 可以很好地导入 torch 包,但 pytest 不能; ModuleNotFoundError
【发布时间】:2022-06-30 07:25:29
【问题描述】:

我正在使用安装了 PyTorch 的 conda。我有以下文件test.py:

import torch

def test_test():
    print(torch.Tensor([1,2]))

test_test()

运行python test.py 工作正常:

> python test.py
tensor([1., 2.])

但是使用pytest 运行它会给我一个错误:

> pytest test.py
(...)
ModuleNotFoundError: No module named 'torch'`.

这里有什么问题?

【问题讨论】:

    标签: python import pytest


    【解决方案1】:

    pytest 是全局安装的,而不是在 coda 环境中。使用conda install pytest 安装它解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多