ImportError: cannot import name 'gen' from 'tornado' (unknown location)

Viewed 1789

I am trying to reinstall pip in my Mac. However, I am still running into the following error. I tried to fix it by deleting pip, but even when I try to reinstall it, the same problem keeps occurring.

  python3 get-pip.py 
Traceback (most recent call last):
  File "get-pip.py", line 24298, in <module>
    main()
  File "get-pip.py", line 139, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 115, in bootstrap
    monkeypatch_for_cert(tmpdir)
  File "get-pip.py", line 96, in monkeypatch_for_cert
    from pip._internal.commands.install import InstallCommand
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/commands/__init__.py", line 9, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/cli/base_command.py", line 12, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/cli/cmdoptions.py", line 23, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/cli/parser.py", line 12, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/configuration.py", line 27, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_internal/utils/misc.py", line 38, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_vendor/tenacity/__init__.py", line 523, in <module>
  File "/var/folders/l1/1bh_mwmx7f18zxjcj0fpysm00000gn/T/tmpeubjpxiw/pip.zip/pip/_vendor/tenacity/tornadoweb.py", line 23, in <module>
ImportError: cannot import name 'gen' from 'tornado' (unknown location)

Maybe anyone has a solution on how to fix this problem.

3 Answers

I had the same problem, so I uninstalled Python and reinstalled. However, the issue with pip continued.

So, I came up with an additional solution:

  1. Uninstall Python
  2. Go to the folder that had the python installation. You will see that files remain in the folder; delete all the files in that folder.
  3. Reinstall Python
  4. Check if your environment variable was set

I was getting a similar but slightly different error trying to use Plotly in Jupyter Lab:

ImportError: cannot import name 'gen' from 'tornadofake' (unknown location)

This seems to be caused by a bug in Matplotlib that causes it to mistakenly replace tornado with a fake module tornadofake, fixed in https://github.com/matplotlib/ipympl/commit/f7579cbdf36838c610d3796fb273b1cddda17903.

Since the bug fix doesn't seem to be available in packages yet, a workaround for me is to import tenacity (from which the error was originating) before doing anything Matplotlib-related.

Perhaps you don't need to reinstall python, if you have also got locally 3.6. 3.7 or 3.9 I copied the pip folder (20.x) from python version 3.9 to 3.8 (on Win10 I got only pip or wheels based installs)

After that I had to reinstall some modules, +- 6, but I specified the tornado version

pip install tornado=5.1.1

so make sure that : pip v. <= 21.1.0

Related