RDFLib / pySHACL

A Python validator for SHACL
Apache License 2.0
241 stars 63 forks source link

setuptools is required but not specified as dependency #188

Closed dalito closed 8 months ago

dalito commented 1 year ago

pyshacl uses pkg_resources which comes with setuptools, e.g. here. For a long time setuptools was a given in virtual environments but it is not anymore and should be explicitly specified.

Typical traceback :

(...)
    import pyshacl
.venv\Lib\site-packages\pyshacl\__init__.py:5: in <module>
    from .validate import Validator, validate
.venv\Lib\site-packages\pyshacl\validate.py:28: in <module>
    from .extras import check_extra_installed
.venv\Lib\site-packages\pyshacl\extras\__init__.py:6: in <module>
    import pkg_resources
E   ModuleNotFoundError: No module named 'pkg_resources'
dalito commented 1 year ago

The "real" fix seems to be using importlib as described here: https://setuptools.pypa.io/en/latest/pkg_resources.html

ashleysommer commented 1 year ago

Hi @dalito thanks for the bug report.

While reading this, I was thinking "I'm sure setuptools was listed as a dependency", and I found this PR from last year that removed the distutils dependency and moved to packaging but there was no mention of setuptools.

I suppose I mistakenly thought the pkg_resources module came with distutils but didn't think to check it when it was replaced with packaging. But in reality I was relying on every system install and venv environment having setuptools installed by default.

The importlib.resources module introduced in Python 3.7 seems like it will be a suitable replacement. I couldn't use that when I wrote this feature because PySHACL targeted Python 3.6 back then, but now Python 3.7 is the minimum, it should be fine to use.

ashleysommer commented 8 months ago

@dalito thanks for your patience on this, the new version with this fix is out now. Note, PySHACL still does not officially support python 3.12, and the application is not tested on python 3.12, so if you're using 3.12 you may run into other issues.