Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: No module named 'pkg_resources' #1619

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

abdrysdale
Copy link

Fixes #1618 add setuptools as a requirement.

@fabclmnt fabclmnt self-requested a review July 12, 2024 18:13
Copy link
Contributor

@fabclmnt fabclmnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @abdrysdale ,

thank you for your contribution. Nevertheless, it is odd that installing the setuptools is the solution for the issue. The behaviour that you are getting seems to be related with something more as we are not being able to replicate.

Here is a screenshot of a conda environment that I've just created and where I've installed ydata-profiling.

image

I would prefer to avoid adding the dependency to setuptools given this is something that is only needed to be installed in case you are building python yourself.

I would put it as something optional in case the user is aware it is missing it in its environment.

@fabclmnt
Copy link
Contributor

Also, can you please make sure that your PR follows the naming and convention so that we are able to build the versions of the package automatically (eg. fix: (message), feat: (message), etc.)

@abdrysdale abdrysdale changed the title Included setuptools in requirements fix: No module named 'pkg_resources' Jul 16, 2024
@abdrysdale
Copy link
Author

abdrysdale commented Jul 16, 2024

I've managed to confirm this on my Windows PC by running the following:

def test():

    # Ensure setuptools has not been installed alongside ydata_profiling
    try:
        import setuptools
        print("Setup tools was already installed - it shouldn't be!")
        assert False
        
    except ModuleNotFoundError as exception:
        assert str(exception) == "No module named 'setuptools'"

    # This fails with: ModuleNotFoundError: No module named 'pkg_resources'
    import ydata_profiling
        

if __name__ == "__main__":
    test()

Which fails with:

  File "C:\Users\foo\AppData\Local\pypoetry\Cache\virtualenvs\ydata-test-w9_z196s-py3.12\Lib\site-packages\ydata_profiling\profile_report.py", line 9, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

The test repository only manually installed ydata_profilling:

annotated-types==0.7.0 ; python_full_version == "3.12.4"
attrs==23.2.0 ; python_full_version == "3.12.4"
certifi==2024.7.4 ; python_full_version == "3.12.4"
charset-normalizer==3.3.2 ; python_full_version == "3.12.4"
colorama==0.4.6 ; python_full_version == "3.12.4" and platform_system == "Windows"
contourpy==1.2.1 ; python_full_version == "3.12.4"
cycler==0.12.1 ; python_full_version == "3.12.4"
dacite==1.8.1 ; python_full_version == "3.12.4"
fonttools==4.53.1 ; python_full_version == "3.12.4"
htmlmin==0.1.12 ; python_full_version == "3.12.4"
idna==3.7 ; python_full_version == "3.12.4"
imagehash==4.3.1 ; python_full_version == "3.12.4"
jinja2==3.1.4 ; python_full_version == "3.12.4"
joblib==1.4.2 ; python_full_version == "3.12.4"
kiwisolver==1.4.5 ; python_full_version == "3.12.4"
llvmlite==0.43.0 ; python_full_version == "3.12.4"
markupsafe==2.1.5 ; python_full_version == "3.12.4"
matplotlib==3.9.1 ; python_full_version == "3.12.4"
multimethod==1.12 ; python_full_version == "3.12.4"
networkx==3.3 ; python_full_version == "3.12.4"
numba==0.60.0 ; python_full_version == "3.12.4"
numpy==1.26.4 ; python_full_version == "3.12.4"
packaging==24.1 ; python_full_version == "3.12.4"
pandas==2.2.2 ; python_full_version == "3.12.4"
patsy==0.5.6 ; python_full_version == "3.12.4"
phik==0.12.4 ; python_full_version == "3.12.4"
pillow==10.4.0 ; python_full_version == "3.12.4"
pydantic-core==2.20.1 ; python_full_version == "3.12.4"
pydantic==2.8.2 ; python_full_version == "3.12.4"
pyparsing==3.1.2 ; python_full_version == "3.12.4"
python-dateutil==2.9.0.post0 ; python_full_version == "3.12.4"
pytz==2024.1 ; python_full_version == "3.12.4"
pywavelets==1.6.0 ; python_full_version == "3.12.4"
pyyaml==6.0.1 ; python_full_version == "3.12.4"
requests==2.32.3 ; python_full_version == "3.12.4"
scipy==1.13.1 ; python_full_version == "3.12.4"
seaborn==0.13.2 ; python_full_version == "3.12.4"
six==1.16.0 ; python_full_version == "3.12.4"
statsmodels==0.14.2 ; python_full_version == "3.12.4"
tqdm==4.66.4 ; python_full_version == "3.12.4"
typeguard==4.3.0 ; python_full_version == "3.12.4"
typing-extensions==4.12.2 ; python_full_version == "3.12.4"
tzdata==2024.1 ; python_full_version == "3.12.4"
urllib3==2.2.2 ; python_full_version == "3.12.4"
visions[type-image-path]==0.7.6 ; python_full_version == "3.12.4"
wordcloud==1.9.3 ; python_full_version == "3.12.4"
ydata-profiling==4.9.0 ; python_full_version == "3.12.4"

@abdrysdale
Copy link
Author

abdrysdale commented Jul 16, 2024

Nevertheless, it is odd that installing the setuptools is the solution for the issue

How so? pkg_resources is part of setuptools (https://setuptools.pypa.io/en/latest/pkg_resources.html) so if setuptools isn't installed then pkg_resources won't be installed.

Can you confirm that setuptools isn't installed globally or elsewhere and that's why you're not getting the same error? Have you tried on a fresh VM?

I've found a stack overflow post that seems to be having the same problem: https://stackoverflow.com/questions/78736427/importerror-cannot-import-name-pkg-resources-from-ydata-profiling

@abdrysdale abdrysdale requested a review from fabclmnt July 19, 2024 13:53
@jklaise
Copy link

jklaise commented Nov 15, 2024

@fabclmnt I suggest reproducing using a Python 3.12 venv as from Python 3.12 setuptools is no longer bundled, see https://docs.python.org/3/whatsnew/3.12.html:

gh-95299: Do not pre-install setuptools in virtual environments created with venv. This means that distutils, setuptools, pkg_resources, and easy_install will no longer available by default; to access these run pip install setuptools in the activated virtual environment.

Note that conda virtual envs might still bundle setuptools so the issue might not be apparent if using conda with Python 3.12. In short, imo adding setuptools as an explicit dependency for python>=3.12 seems to be the right solution until the library migrates from pkg_resources to importlib.resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ModuleNotFoundError: No module named 'pkg_resources'
3 participants