pandaspython-3.7

Getting Error while running python3 main.py file


I am getting this error,

/tmp/Python-3.7.5$ python3 main.py
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import pandas as pd
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/__init__.py", line 51, in <module>
    from pandas.core.api import (
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/core/api.py", line 31, in <module>
    from pandas.core.groupby import Grouper, NamedAgg
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
    from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/core/groupby/generic.py", line 65, in <module>
    from pandas.core.frame import DataFrame
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/core/frame.py", line 119, in <module>
    from pandas.core import algorithms, common as com, generic, nanops, ops
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/core/generic.py", line 112, in <module>
    from pandas.io.formats import format as fmt
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/io/formats/format.py", line 77, in <module>
    from pandas.io.common import stringify_path
  File "/home/abc/.local/lib/python3.7/site-packages/pandas/io/common.py", line 3, in <module>
    import bz2
  File "/usr/local/lib/python3.7/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'

what is the solution?


Solution

  • How did you install your Python? If you've manually built it or used the make command, you might be missing the bz2 library headers.

    Try the following...

    Centos/Fedora/RHEL:

    sudo yum install bzip2-devel 
    

    Debian and Ubuntu:

    sudo apt-get install libbz2-dev
    

    You'll then either need to rebuild your Python installation or to copy the header in your Python folder, with:

    sudo cp /usr/lib/python3.7/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so  /usr/local/lib/python3.7/