AS me if you want to use plotly.express module and you fail with somethink like :

ImportError: Plotly express requires pandas to be installed.

It seems obvious : “pip3 install pandas”. But it can fail with :

>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/__init__.py", line 48, in <module>
from pandas.core.api import (
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/api.py", line 47, in <module>
from pandas.core.groupby import (
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
from pandas.core.groupby.generic import (
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 77, in <module>
from pandas.core.frame import DataFrame
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/frame.py", line 171, in <module>
from pandas.core.generic import NDFrame
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/generic.py", line 148, in <module>
from pandas.core.describe import describe_ndframe
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/core/describe.py", line 43, in <module>
from pandas.io.formats.format import format_percentiles
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/io/formats/format.py", line 105, in <module>
from pandas.io.common import (
File "/root/src/tango-batch/venv/lib/python3.9/site-packages/pandas/io/common.py", line 8, in <module>
import bz2
File "/usr/local/lib/python3.9/bz2.py", line 18, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

the way to correct it (if as me you have compiled your version of Python) :

apt-get install libbz2-dev

And go to :

./configure --prefix=/usr/local && make && make install

You could normally do some :

(venv) root@SERVER:~/src/project# python3 
Python 3.9.14 (main, Sep 20 2022, 17:54:59) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> import plotly.express as px

Have fun !

Python3 and plotly.express : if it fails to import…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.