微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 conda 环境激活的情况下在 powershell 中使用 Python

如何解决在 conda 环境激活的情况下在 powershell 中使用 Python

我有一个名为 condaml 环境,我已使用以下命令在 powershell 中激活此环境:

>> conda init powershell
>> conda activate ml
(ml) >>

当我使用 jupyter notebook 命令打开笔记本时,它工作正常并且我可以访问 ml 环境中的模块:

import torch  # No errors inside a jupyter notebook cell

但是当我尝试在 powershell 和 Python 提示符下测试我的模块时,它不起作用:

(ml) >> py
Python 3.8.6 (tags/v3.8.6:db45529,Sep 23 2020,15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
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'

我是 conda 环境的新手。有没有办法在 windows powershell 的 Python 提示中使用 conda 环境?

解决方法

使用以下方法确保 pytorch 安装在您的环境中:

conda install -c pytorch pytorch
,

我认为 powershell 中的 conda 初始化一定有问题,请在完成初始化后尝试重新启动 powershell

conda init powershell

然后激活环境然后它应该可以工作

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。