【问题标题】:Use Python in powershell with conda environment activated在激活了 conda 环境的 powershell 中使用 Python
【发布时间】:2021-07-18 08:57:44
【问题描述】:

我有一个名为mlconda 环境,我已使用以下命令在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 环境?

【问题讨论】:

    标签: python powershell jupyter-notebook anaconda conda


    【解决方案1】:

    确保pytorch 已安装在您的环境中,使用:

    conda install -c pytorch pytorch
    

    【讨论】:

    • 这不仅仅是关于 pytorch。 import seaborn as snsimport pandas as pd 也会导致错误,虽然它们已经安装在环境中。
    • @Tabaraei conda listm1 中的输出是什么?
    • 有很多,但我可以向你保证,pytorch、seaborn 和 pandas 都在那里。
    【解决方案2】:

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

    conda init powershell
    

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

    【讨论】:

    • 我已经重启了powershell。我也用你的解决方案又做了一次,但是没有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2019-08-03
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    相关资源
    最近更新 更多