9

I installed Jupyter notebook and labs on and EC2 instance and for some reason I get the following error:

ImportError: cannot import name 'filefind' from 'traitlets.utils' (/usr/lib/python3/dist-packages/traitlets/utils/init.py)

Jupyter opens fine in the browser but I can't seem to be able to work in an python notebook.

Rick Vink
  • 321
  • 1
  • 3
  • 11

4 Answers4

19

I disencourage the solution of op. Downloading and overwriting python libraries is not the way of keeping your system stable and clean!

What I found out is that while installing Jupyter notebook it had found four significant errors which resulted from python3 packages that were not installed correctly within that installation itself.

ERROR: ipykernel 6.6.0 has requirement traitlets<6.0,>=5.1.0, but you'll have traitlets 4.3.3 which is incompatible. ERROR: jupyterlab-pygments 0.1.2 has requirement pygments<3,>=2.4.1, but you'll have pygments 2.3.1 which is incompatible. ERROR: nbconvert 6.3.0 has requirement pygments>=2.4.1, but you'll have pygments 2.3.1 which is incompatible. ERROR: nbconvert 6.3.0 has requirement traitlets>=5.0, but you'll have traitlets 4.3.3 which is incompatible.

The solution is to just patch the packages to the newest version with:

pip3 install traitlets==5.1.1

pip3 install pygments==2.4.1

This applies to all similar cases where outdated packages prevent you from your installation

luarzou
  • 306
  • 1
  • 5
  • I agree that it is indeed dirty. The reason why I did it this way is because I think it will be fixed in the future and I just wanted to continue with my work ;). This is indeed not something that should be a standard practice for installation. – Rick Vink Dec 19 '21 at 14:29
  • I you do not mind you can accept my answer as one that solves the problem :) – luarzou Jan 26 '22 at 18:41
  • Hehe sure, enjoy the stackoverflow kudos =). I didn't use your method but looking at the +1's it should be good. – Rick Vink Jan 27 '22 at 21:33
5

Dirty initial fix (not recommended):

Oke fixed it! It seems like the problem was that the "traitlets/utils/init.py" was empty. So I copy-pasted the code from GitHub and that worked.

https://github.com/ipython/traitlets/blob/main/traitlets/utils/__init__.py

I got this problem twice when I installed two different ec2 instances installing cuda and cudnn. So it might that this has something to do with the origins of this issue.

Proper fix:

The proper way to fix this problem is by upgrading/downgrading the library. Check the other answers to this post for guidance.

Rick Vink
  • 321
  • 1
  • 3
  • 11
  • Hm, I had the same issue and have no clue what might have caused it—this fixed it though! I've been installing a bunch of different python versions lately in an attempt to get tensorflow running on M1, so maybe that had something to do with it. – Simon Alford Nov 16 '21 at 21:56
  • Please consider removing this answer. This is not really the way to fix this problem. – Carlos Cordoba Feb 05 '22 at 21:51
  • I will edit the post to make it clear – Rick Vink Feb 06 '22 at 09:00
3

I faced the same issue. Downgrading the versions of traitlets and pygments alone, as suggested by @luarzou, didn't solved the problem for me. I also downgrade ipykernel and it works now:

pip install ipykernel==6.0

I opened an issue: https://github.com/ipython/ipykernel/issues/857

Edit: actually this error can happen when your venv has versions of ipykernel or its dependencies different than the env running jupyter. I suggest in that case to delete and recreate your venv, and verify that you don't install there packages that will break the communication/compatibility.

steco
  • 1,303
  • 13
  • 16
1

I had the same issue on all env other than the base. Even installed the same version of traitlets, pygments and ipykernel as in base,it also failed. After a couple of searches, I removed traitlets using

sudo apt-get remove python3-traitlets
sudo apt-get remove --auto-remove python3-traitlets

Then I installed jupyter

conda install notebook ipykernel jupyterlab

This solved my issue on all environments

Aleesha s j
  • 121
  • 1
  • 4