报错ModuleNotFoundError: No module named ‘IPython‘

博主在Anaconda环境中遇到IPython模块未找到的问题,虽然已安装但命令行交互正常。通过对比发现,在不同环境下IPython可用性不同,最终通过重新安装解决了这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天的这个报错比较有意思,在anaconda环境下,

ModuleNotFoundError: No module named 'IPython'

赶紧测试了一下,发现ipython已经安装且一点问题都没有,

(torch) PS D:\vsai\evaluate> ipython
Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: ?

IPython -- An enhanced Interactive Python
=========================================

IPython offers a fully compatible replacement for the standard Python
interpreter, with convenient shell features, special commands, command
history mechanism and output results caching.

At your system command line, type 'ipython -h' to see the command line
options available. This document only describes interactive features.

GETTING HELP
------------

Within IPython you have various way to access help:

  ?         -> Introduction and overview of IPython's features (this screen).
  object?   -> Details about 'object'.
  object??  -> More detailed, verbose information about 'object'.
  %quickref -> Quick reference of all IPython specific syntax and magics.
  help      -> Access Python's own help system.

If you are in terminal IPython you can quit this screen by pressing `q`.


MAIN FEATURES
-------------

* Access to the standard Python help with object docstrings and the Python
  manuals. Simply type 'help' (no quotes) to invoke it.

* Magic commands: type %magic for information on the magic subsystem.

* System command aliases, via the %alias command or the configuration file(s).

* Dynamic object information:

  Typing ?word or word? prints detailed information about an object. Certain
  long strings (code, etc.) get snipped in the center for brevity.

  Typing ??word or word?? gives access to the full information without

In [2]: quit
(torch) PS D:\vsai\evaluate> python

那么,为什么会找不到ipython呢?决定再试,

(torch) PS D:\vsai\evaluate> python

Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import IPython
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'IPython'
>>> exit()
(torch) PS D:\vsai\evaluate>

从这里可以看出,anaconda在通用命令行环境时可以找到ipython,但是,在创建的torch环境下找不到ipython,因此import IPython无法成功,因此,再安装一下就可以了,如下

(torch) PS D:\vsai\evaluate> conda install -c anaconda ipython
。。。。。。

通用anaconda安装,当然也可以用pip安装,不过我这里已经OK了,就不再试了。

然后,在python中再测试,就有了,嗯,我自己还加了一句测试打印代码。

(torch) PS D:\vsai\evaluate> python
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import IPython
---------------------subprocess.checkout--------------------
>>> exit()
(torch) PS D:\vsai\evaluate>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值