0

According to the pandasgui docs I tried to run the following code:

import pandas as pd
from pandasgui import show
df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]})
show(df)

However, I get an error:

ImportError: cannot import name '_c_internal_utils' from partially initialized module 'matplotlib' (most likely due to a circular import) (C:\ProgramData\Anaconda3\envs\Test\lib\site-packages\matplotlib\__init__.py)

According to this post it seems related to the fact that pands and pandasgui import statements both use the same reference to a matploblib function/module, so there is a circular import. I tried to change the code to

import pandas as pd
import pandasgui
df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6], 'c':[7,8,9]})
pandasgui.show(df)

But I get the same error. How can I fix this?

My python is version 3.11.4 | packaged by Anaconda, Inc.

My pandas is version 2.03 it was already installed in my anaconda environment by default and I updated it with the Anaconda navigator.

My pandasgui is version 0.2.14 and I installed it with pip install pandasgui. I updated the index in Anaconda navigator and it also displays version 0.2.14

PSt
  • 97
  • 11
  • 1
    How it happened that your site packages are in `ypy1\lib`? Did you run `pip install pandasgui` when your conda env was active? Where exactly did you run `pip ...`? – Vitalizzare Aug 28 '23 at 12:15
  • My apologies! The error message in that part was wrong, I updated it. I could not find pandasgui via anaconda navigator. So from anaconda navigator I started Jupyter notebook and there I run the pip command. – PSt Aug 28 '23 at 13:21

1 Answers1

0

As the error suggests, I can see a circular import occur when two or more modules depend on each other. This mutual dependency creates a cycle, which Python doesn't handle well.

Sometimes there might be package conflicts if you've installed multiple packages or their different versions. Try to create a new conda environment:

conda create --name newenv python=3.11
conda activate newenv

Now, install the required packages in this clean environment:

pip install pandas
pip install pandasgui

Run your code within this new environment.

Sometimes, it's a specific version of a dependent library causing the issue. You can try downgrading matplotlib to see if that resolves the problem:

pip install matplotlib==3.4.2

Then run your code again.

Also, ensure all your packages are up-to-date:

pip install pandasgui --upgrade
pip install pandas --upgrade
pip install matplotlib --upgrade
Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
  • When I try to run conda create test newenv python=3.11 I get an error message: CondaValueError: The target prefix is the base prefix. Aborting – PSt Aug 28 '23 at 13:33
  • The error message CondaValueError: The target prefix is the base prefix. Aborting typically occurs when conda thinks you're trying to overwrite or modify the base environment (the main environment where conda itself is installed), which is not what you usually want to do. – Amira Bedhiafi Aug 29 '23 at 10:45
  • Well I just run the code you posted with the name test and I also tried another name. It is not the name of my base environment. – PSt Aug 29 '23 at 11:00
  • What is the name of your base environment then ? – Amira Bedhiafi Aug 29 '23 at 11:27
  • It is base (root). – PSt Aug 29 '23 at 12:09