You are not logged in.

#1 2018-11-05 17:41:48

thund3rpantz
Member
Registered: 2013-12-13
Posts: 32

[Solved] Jupyter-notebook crashes with import error

When opening a python kernel in jupyter, it crashes.
This happened after removing all packages installed with pip, to install them with pacman.

I tried removing anything i could and reinstall python using

$ sudo python -S jupyter

$ python -c 'import prompt_toolkit.eventloop; print(prompt_toolkit.eventloop.__file__)'

still returns:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/__init__.py", line 16, in <module>
    from .interface import CommandLineInterface
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/interface.py", line 19, in <module>
    from .application import Application, AbortAction
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/application/__init__.py", line 2, in <module>
    from .application import Application
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 3, in <module>
    from prompt_toolkit.buffer import Buffer
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/buffer.py", line 9, in <module>
    from .completion import Completer, Completion, CompleteEvent
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/completion/__init__.py", line 2, in <module>
    from .base import Completion, Completer, ThreadedCompleter, DummyCompleter, DynamicCompleter, CompleteEvent, merge_completers, get_common_complete_suffix
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 4, in <module>
    from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGeneratorItem
ImportError: cannot import name 'generator_to_async_generator' from 'prompt_toolkit.eventloop' (/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/__init__.py)

Last edited by thund3rpantz (2018-11-06 16:34:34)

Offline

#2 2018-11-06 09:48:52

spinnau
Member
Registered: 2017-06-05
Posts: 38

Re: [Solved] Jupyter-notebook crashes with import error

thund3rpantz wrote:

I tried removing anything i could and reinstall python using

$ sudo python -S jupyter

Probably you meant reinstalling the package with pacman?

$ sudo pacman -S jupyter



thund3rpantz wrote:

$ python -c 'import prompt_toolkit.eventloop; print(prompt_toolkit.eventloop.__file__)'

still returns:

....
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/completion/base.py", line 4, in <module>
    from prompt_toolkit.eventloop import generator_to_async_generator, AsyncGeneratorItem
ImportError: cannot import name 'generator_to_async_generator' from 'prompt_toolkit.eventloop' (/usr/lib/python3.7/site-packages/prompt_toolkit/eventloop/__init__.py)

That file `prompt_toolkit/completion/base.py` doesn't exist in the community package python-prompt_toolkit 1.0.15-2. It seems you have installed a version 2.0.x, e.g. from AUR.
Jupyter notebook and prompt_toolkit works fine for me with the community packages.

Last edited by spinnau (2018-11-06 09:52:27)

Offline

#3 2018-11-06 16:17:21

thund3rpantz
Member
Registered: 2013-12-13
Posts: 32

Re: [Solved] Jupyter-notebook crashes with import error

Hmm. my installed prompt_toolkit it also version 1.0.15-2, as i installed it together with python and the jupyter package.
Why is is tried imported?

But you are right, I had promt_toolkit-2.0.6.dist-info in /usr/lib/python3.7/site-packages. most likely installed using pip.
So i have learned the hard way why not use pip outside a virtual environment.

Removing the folder did not change anything.

What is the best way to remove all installed python packages and start from scratch?

Offline

#4 2018-11-06 16:33:45

thund3rpantz
Member
Registered: 2013-12-13
Posts: 32

Re: [Solved] Jupyter-notebook crashes with import error

Might not be the safest way, so be careful if anyone is doing the same thing:

sudo pacman -Rsc python python2   !!!! Be careful, this might remove much more than wanted!
sudo rm -rf /usr/lib/python*
pacman -Syu python jupyter-notebook

This approach worked, but I feel dirty.
I'm only going installing python packages with pacman from now on.
Thanks for the help!

Offline

#5 2018-11-06 17:08:37

spinnau
Member
Registered: 2017-06-05
Posts: 38

Re: [Solved] Jupyter-notebook crashes with import error

To remove files from the system folders that you have installed without pacman please see https://wiki.archlinux.org/index.php/Pa … ny_package


If you want to install packages with pip e.g. because there is no official arch package for that or you want a newer version of that python package, then you can install it as user. The package will then be installed to ~/.local/lib/python3.7/site-packages. You can also safely delete unwanted packages there without breaking your system.

$ pip install package-name --user

If the package should be installed system wide, then creating a PKGBUILD should be preferred over letting pip copy the files to your system. Maybe someone already created an AUR package for that ;-)

Offline

#6 2018-11-06 19:35:00

thund3rpantz
Member
Registered: 2013-12-13
Posts: 32

Re: [Solved] Jupyter-notebook crashes with import error

Thanks for the tip!

Offline

Board footer

Powered by FluxBB