jupyter_core icon indicating copy to clipboard operation
jupyter_core copied to clipboard

Draft7Validator(TyperError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry'

Open jclsn opened this issue 2 years ago • 25 comments

Getting this error with the latest Arch package version

❯ jupyter --version
Selected Jupyter core packages...
IPython          : 8.16.0
ipykernel        : 6.25.2
ipywidgets       : not installed
jupyter_client   : 8.4.0
jupyter_core     : 5.4.0
jupyter_server   : 2.8.0
Traceback (most recent call last):
  File "/usr/bin/jupyter", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyter_core/command.py", line 261, in main
    mod = __import__(package)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/jupyterlab/__init__.py", line 8, in <module>
    from .handlers.announcements import (
  File "/usr/lib/python3.11/site-packages/jupyterlab/handlers/announcements.py", line 14, in <module>
    from jupyter_server.base.handlers import APIHandler
  File "/usr/lib/python3.11/site-packages/jupyter_server/base/handlers.py", line 24, in <module>
    from jupyter_events import EventLogger
  File "/usr/lib/python3.11/site-packages/jupyter_events/__init__.py", line 3, in <module>
    from .logger import EVENTS_METADATA_VERSION, EventLogger
  File "/usr/lib/python3.11/site-packages/jupyter_events/logger.py", line 19, in <module>
    from .schema import SchemaType
  File "/usr/lib/python3.11/site-packages/jupyter_events/schema.py", line 18, in <module>
    from .validators import draft7_format_checker, validate_schema
  File "/usr/lib/python3.11/site-packages/jupyter_events/validators.py", line 44, in <module>
    JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator(
                                      ^^^^^^^^^^^^^^^^
TypeError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry'

jclsn avatar Oct 23 '23 07:10 jclsn

Getting the same issue here - did you manage to figure out the cause?

Versions for mine (in case it helps triangulate):

(.venv) jupyter --version
Selected Jupyter core packages...
IPython          : 8.18.1
ipykernel        : 6.27.1
ipywidgets       : 8.1.1
jupyter_client   : 8.6.0
jupyter_core     : 5.5.0
jupyter_server   : 2.12.1
Traceback (most recent call last):

AdamLuchjenbroers avatar Dec 15 '23 00:12 AdamLuchjenbroers

Aha - for me the culprit was apparently an older version of jsonschema that had been pulled in as a dependency by another python module.

AdamLuchjenbroers avatar Dec 15 '23 02:12 AdamLuchjenbroers

I am having the same problem in Ubuntu 20.04 in pipenv and poetry envs as well. Any ideas how to fix it?

jupyter --version
Selected Jupyter core packages...
IPython          : 8.18.1
ipykernel        : 6.27.1
ipywidgets       : 8.1.1
jupyter_client   : 8.6.0
jupyter_core     : 5.5.1
jupyter_server   : 2.12.1
Traceback (most recent call last):
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/bin/jupyter", line 8, in <module>
    sys.exit(main())
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_core/command.py", line 260, in main
    mod = __import__(package)
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyterlab/__init__.py", line 8, in <module>
    from .handlers.announcements import (
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyterlab/handlers/announcements.py", line 14, in <module>
    from jupyter_server.base.handlers import APIHandler
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_server/base/handlers.py", line 23, in <module>
    from jupyter_events import EventLogger
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_events/__init__.py", line 3, in <module>
    from .logger import EVENTS_METADATA_VERSION, EventLogger
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_events/logger.py", line 19, in <module>
    from .schema import SchemaType
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_events/schema.py", line 18, in <module>
    from .validators import draft7_format_checker, validate_schema
  File "/home/xxx/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/pythonProject-SksRS6Wi/lib/python3.10/site-packages/jupyter_events/validators.py", line 44, in <module>
    JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator(
TypeError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry'

mat-l avatar Dec 20 '23 10:12 mat-l

Downgrading jsonschema from the latest 4.20.0 to 4.19.2 solved the issue for me, fyi.

gokceneraslan avatar Jan 03 '24 17:01 gokceneraslan

@Julian Any suggestions?

gokceneraslan avatar Jan 03 '24 17:01 gokceneraslan

How does one reproduce the issue being reported here?

Julian avatar Jan 03 '24 17:01 Julian

Running jupyter --version as shown above (or in my case running jupyter-lab) triggers the error when jsonschema 4.20.0 is installed.

gokceneraslan avatar Jan 03 '24 17:01 gokceneraslan

Should this line now also include <4.20.0?

gokceneraslan avatar Jan 03 '24 17:01 gokceneraslan

That produces no error here.

⊙  python3.12 -m venv venv && PYTHONWARNINGS=ignore venv/bin/pip install --quiet jupyter && venv/bin/jupyter --version                                                                                                                                                                                              julian@Airm

[notice] A new release of pip is available: 23.3.1 -> 23.3.2
[notice] To update, run: python3.12 -m pip install --upgrade pip
/Users/julian/Desktop/venv/lib/python3.12/site-packages/jupyter_core/command.py:23: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
given by the platformdirs library.  To remove this warning and
see the appropriate new directories, set the environment variable
`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
The use of platformdirs will be the default in `jupyter_core` v6
  from . import paths
Selected Jupyter core packages...
IPython          : 8.19.0
/Users/julian/Desktop/venv/lib/python3.12/site-packages/dateutil/tz/tz.py:37: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
  EPOCH = datetime.datetime.utcfromtimestamp(0)
ipykernel        : 6.28.0
ipywidgets       : 8.1.1
jupyter_client   : 8.6.0
jupyter_core     : 5.7.0
jupyter_server   : 2.12.1
jupyterlab       : 4.0.10
nbclient         : 0.9.0
nbconvert        : 7.14.0
nbformat         : 5.9.2
notebook         : 7.0.6
qtconsole        : 5.5.1
traitlets        : 5.14.1

(and for reference:

⊙  venv/bin/python -m pip show jsonschema                                                                                                                                                                                                                                                                           julian@Airm
Name: jsonschema
Version: 4.20.0
Summary: An implementation of JSON Schema validation for Python
Home-page: 
Author: Julian Berman
Author-email: [email protected]
License: MIT
Location: /Users/julian/Desktop/venv/lib/python3.12/site-packages
Requires: attrs, jsonschema-specifications, referencing, rpds-py
Required-by: jupyter-events, jupyterlab_server, nbformat

Julian avatar Jan 03 '24 17:01 Julian

Wait, now I updated jsonschema to 4.20.0 and I cannot reproduce the error. I really didn't change anything in between...

gokceneraslan avatar Jan 03 '24 18:01 gokceneraslan

how to slove it ?

liuchenbaidu avatar Jan 31 '24 12:01 liuchenbaidu

Hit same error

  File "/Users/sophia/.pyenv/versions/3.11.2/lib/python3.11/site-packages/jupyter_events/validators.py", line 44, in <module>
    JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator(
                                      ^^^^^^^^^^^^^^^^
TypeError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry'

I solved it by

pip install --upgrade jupyterlab jupyterlab_server jupyter_server traitlets nbformat

as per this post

fengs avatar Feb 01 '24 19:02 fengs

@fengs Your answer above solved my issue as well.

weiyunxian80 avatar Apr 03 '24 19:04 weiyunxian80

I'll just note that running that sort of command is exactly the kind of mistake that's likely to have gotten you into this situation.

Specifically, I claim the only way you could have broken your installation is by running that kind of command!

It's true that running a similar one may get you out of it.

But in Python, it is not safe to run repeated installation commands willy nilly.

pip will not save you from running pip install once and then pip install later in a way that might downgrade a thing you installed. In short: it is a user error if you ever run pip install --upgrade essentially in my opinion, but you doing it twice may indeed fix something (and perhaps break another!).

Julian avatar Apr 03 '24 20:04 Julian

@Julian Keep in mind that some of us develop in environments where we only have partial admin rights. Your assumption is incorrect as I did a full install, and for whatever reason, I get the error above. (Keep in mind that I've used dozens of laptops/desktops over the past 3 years and only recently experienced this issue)

I'll add that I fully agree this will very likely cause versioning issues in the not-too-distant future...

weiyunxian80 avatar Apr 03 '24 20:04 weiyunxian80

While I don't blame you as a user, my message is precisely to eliminate:

Your assumption is incorrect as I did a full install, and for whatever reason, I get the error above. (Keep in mind that I've used dozens of laptops/desktops over the past 3 years and only recently experienced this issue)

There is I claim no way this could happen. If there were, I would love to see it, and would be happy to look into it. Otherwise though, my assumption remains, I assume the only way any user could get into this state is by doing something as I say causes general poor behavior and isn't supported (namely running partial installs).

Julian avatar Apr 03 '24 20:04 Julian

@Julian This occurred after I did a fresh install and then installed CUDA-enabled PyTorch.

weiyunxian80 avatar Apr 03 '24 20:04 weiyunxian80

A fresh install of what? That sounds precisely like you're saying you did the thing I said causes issues.

Julian avatar Apr 03 '24 20:04 Julian

Apologies for coming across as passive aggressive. I edited my comment after re-reading it and realizing I sounded like an arse.

I downloaded and did a clean install of the most recent version of Anaconda. The only thing I can think of that I did that could have possibly caused an issue was from installing PyTorch and CUDA. However, I created a virtual env before doing this, so I don't think it would make the notebook completely break, right?

weiyunxian80 avatar Apr 03 '24 20:04 weiyunxian80

(No worries, I didn't see the edit, but now I do, so now I've edited mine. No hard feelings certainly.)

I downloaded and did a clean install of the most recent version of Anaconda.

But then you ran pip install for the CUDA-enabled PyTorch? Or how did you do that install?

I honestly don't use Anaconda so I am no expert, but I would assume indeed that if you did run pip install to do that that that definitely could cause an issue (As presumably the base environment was set up using conda).

Julian avatar Apr 03 '24 21:04 Julian

As a quick caveat, I am not a fan of using conda for any installs because of the high likelihood for conflicting issues arising from needing to use 'pip install'. B/C of the computing environment my project is in, I am forced to use Anaconda.

I do think I broke it previously by using pip install within a conda environment. After I realized I did that, I uninstalled Anaconda, did a clean install, and then followed the following instructions from the NVidia website:
image

Maybe I'll just try to do everything using pip instead of conda? I'll uninstall, reinstall, and then try this method. I'll post an update after I do this later this evening.

weiyunxian80 avatar Apr 03 '24 21:04 weiyunxian80

Please try: pip install jupyter notebook -U

mousavikahaki avatar Apr 17 '24 13:04 mousavikahaki

Hit same error

  File "/Users/sophia/.pyenv/versions/3.11.2/lib/python3.11/site-packages/jupyter_events/validators.py", line 44, in <module>
    JUPYTER_EVENTS_SCHEMA_VALIDATOR = Draft7Validator(
                                      ^^^^^^^^^^^^^^^^
TypeError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry'

I solved it by

pip install --upgrade jupyterlab jupyterlab_server jupyter_server traitlets nbformat

as per this post

Thanks!

RasoulZardeyni avatar Apr 24 '24 08:04 RasoulZardeyni

I, too, had the experience that the version of jsonschema was to blame! I upgraded jsonschema from 4.17.3 to 4.18.6, and all is good :)

Noticing that another poster had to DOWN-grade from a much more recent version of jsonschema , I didn't dare go past 4.18.6 !

All is good for me now (on Python 3.9) with the following combo of libraries:

jsonschema==4.18.6 jupyterlab==3.6.8 jupytext==1.15.2

My version of jupyterlab-server is 2.27.3

(jupytext is an extension of JupyterLab, to synchronize notebooks and python-file versions of them; very handy!)

BrainAnnex avatar Jan 29 '25 05:01 BrainAnnex

Hi all,

This appears to be issue when running Jupyter web applications, e.g. Lab or Notebook, (which depend on jupyter_events under the hood) with jsonschema < 4.18. Now, jupyter_events has a version specification that calls for jsonschema >= 4.18, but as @Julian alludes to in his comment here:

pip will not save you from running pip install once and then pip install later in a way that might downgrade a thing you installed. In short: it is a user error if you ever run pip install --upgrade essentially in my opinion, but you doing it twice may indeed fix something (and perhaps break another!).

other packages that pin jsonschema might be downgrading this package and causing this error in jupyter web applications.

What would be helpful here is if folks can include the versions of the following package in their report here:

jupyter_server
jupyter_events
jsonschema

My expectation is that cases where jupyter_events>=0.7 and jsonschema<4.18, we see the error reported here.

Zsailer avatar Feb 03 '25 23:02 Zsailer