gpt4 book ai didi

python-3.x - "no module named torch"。但是在 Ubuntu 18.04.02 服务器版中安装了带有 conda 的 pytorch 1.3.0

转载 作者:行者123 更新时间:2023-12-04 02:42:24 43 4
gpt4 key购买 nike

用 conda 安装 pytorch :

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda install  
pytorch torchvision cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

我更新了 conda:

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda update 
conda
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

已安装 mkl=2019 :

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda install  
mkl=2019
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ conda list | grep
torch
cpuonly 1.0 0 pytorch
facenet-pytorch 0.1.0 pypi_0 pypi
pytorch 1.3.0 py3.7_cpu_0 [cpuonly] pytorch
torchfile 0.1.0 pypi_0 pypi
torchvision 0.4.1 py37_cpu [cpuonly] pytorch

但它仍然说“没有模块火炬”:

(base) (3.8.0/envs/my_virtual_env-3.8.0) marco@pc:~/facenet_pytorch/examples$ python3
Python 3.8.0 (default, Oct 30 2019, 16:20:23)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>>

我发现这个问题只出现在python 3.8.0版本

(base) marco@pc:~/facenet_pytorch$ python3
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>

Ubuntu 18.04.02 服务器版

或者,正如您所说,这可能只是 python 环境的问题。但是我不明白为什么只激活conda环境,用“conda activate”,它不起作用

马可

最佳答案

首先使用以下命令创建一个 Conda 环境:

conda create -n pytorch_env python=3 ( you can create with any python version )

使用以下方法激活环境:

conda activate pytorch_env

现在使用以下命令安装 PyTorch:

conda install pytorch-cpu torchvision -c pytorch

转到python shell并使用命令导入:

import torch

关于python-3.x - "no module named torch"。但是在 Ubuntu 18.04.02 服务器版中安装了带有 conda 的 pytorch 1.3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58732358/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com