今天的这个报错比较有意思,在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>

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐