简体   繁体   中英

jupyter-notebook, ImportError: cannot import name 'Type'

I am a Windows user, and I have installed Python 3.6 on my computer. In order to use Jupyter notebooks, I downloaded atom. I already installed ipython and pandas. After entering the command jupyter notebook on the command-line, my browser doesn't open jupyter notebook, instead I get the follow error message:

[C:\Users\ELIDAD>jupyter notebook
Traceback (most recent call last):
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\ELIDAD\AppData\Local\Programs\Python\Python35\Scripts\jupyter-notebook.EXE\__main__.py", line 5, in <module>
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\notebook\__init__.py", line 25, in <module>
    from .nbextensions import install_nbextension
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\notebook\nbextensions.py", line 610, in <module>
    from .extensions import (
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\notebook\extensions.py", line 8, in <module>
    from tornado.log import LogFormatter
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\tornado\log.py", line 34, in <module>
    from tornado.escape import _unicode
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\tornado\escape.py", line 27, in <module>
    from tornado.util import unicode_type
  File "c:\users\elidad\appdata\local\programs\python\python35\lib\site-packages\tornado\util.py", line 21, in <module>
    from typing import (
ImportError: cannot import name 'Type']

So, what is the problem? I am new to python and jupyter notebook. Thank you very much.

是因为Python3.5有自己的版本打字( https://docs.python.org/3/library/typing.html ),和安装的jupyter/tornado版本不兼容升级到python3.6可以解决问题。

Since the error seems to come from the tornado package, i would try to reinstall tornado if this does not help I made the experience that the conda packages often work better in windows: so just reinstall jupyter notebook (best in a new env) using anaconda

Best of luck, installing jupyter notebook used to make me a lot of troubles as well.

If you're using Python 3.5.1 and don't want to use Conda, downgrading the Tornado version allows it run. Current Tornado version is 6.0.3. I downgraded it 4.5.1 because I knew it worked. Other versions after this might also work. It's an easy fix without the need to update the Python version.

I think it will be better to create a virtual environment. Then, re-install jupyter notebook under that environment.

Visit https://www.digitalocean.com/community/tutorials/how-to-set-up-jupyter-notebook-with-python-3-on-ubuntu-18-04

Install anaconda ,

" Anaconda is a free and open-source distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment " (As on google)

and then try Jupyter notebook link: https://www.anaconda.com/distribution/

Python 3.5.1 doesn't have typing.Type, so I upgraded my python version to 3.5.4 which did the trick, for more details, Please check below link

https://stackoverflow.com/a/56159851/7741962

这会发生 bcz python 3.5+ 有自己的类型并且没有 Deque 类,你可以在 protocol.py 中做一件事,从导入状态中删除 Deque 并从集合中导入 Deque 这对我有用

If you want to get rid of the error

ImportError: cannot import name 'Type']

Just upgrade or use Python 3.5.4 that will solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM