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

ModuleNotFoundError: No module named 'distutils' after importing pandas-datareader #992

Open
MLafeta opened this issue Jul 22, 2024 · 2 comments

Comments

@MLafeta
Copy link

MLafeta commented Jul 22, 2024

I've already installed the pandas-datareader on my pycharm however whenever i try to import it i get the following error ModuleNotFoundError: No module named 'distutils'.
I also couldn't find this module 'distutils' on my pycharm. Any idea how to fix it?

@saviornt
Copy link

In the pandas_datareader/compat folder, edit the __init__.py file:

find the line (it's the first one):
from distutils.version import LooseVersion

and replace with:
from packaging.version import Version

On the Version checking lines:

PANDAS_VERSION = LooseVersion(pd.__version__)

PANDAS_0210 = PANDAS_VERSION >= LooseVersion("0.21.0")
PANDAS_0220 = PANDAS_VERSION >= LooseVersion("0.22.0")
PANDAS_0230 = PANDAS_VERSION >= LooseVersion("0.23.0")

Replace LooseVersion with Version:

PANDAS_VERSION = Version(pd.__version__)

PANDAS_0210 = PANDAS_VERSION >= Version("0.21.0")
PANDAS_0220 = PANDAS_VERSION >= Version("0.22.0")
PANDAS_0230 = PANDAS_VERSION >= Version("0.23.0")

@cm-halfspace
Copy link

Or, a slightly easier fix, is to change

from distutils.version import LooseVersion

to

from packaging.version import Version as LooseVersion

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

No branches or pull requests

3 participants