I am trying to run a python code which uses pandas
library. I am getting an error saying that bz2
can not be found. I do not have root access and can not install anything. Is there a way to use pandas
in another way? There are similar questions to mine in stackoverflow but they require root access to install bz2
.
Importing pandas
(Python 3.8.3, CentOS Linux release 7.6.1810 (Core)):
import pandas as pd
output:
Traceback (most recent call last):
File "tmp.py", line 1, in <module>
import pandas as pd
File "/home/myusername/src/dataprocessing/.venv/lib/python3.8/site-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401
File "/home/myusername/src/dataprocessing/.venv/lib/python3.8/site-packages/pandas/compat/__init__.py", line 24, in <module>
import pandas.compat.compressors
File "/home/myusername/src/dataprocessing/.venv/lib/python3.8/site-packages/pandas/compat/compressors.py", line 7, in <module>
import bz2
ModuleNotFoundError: No module named 'bz2'
2
Answers
If
bz2
is not mandatory, you can try to catch the exception:Update
You can also copy
bz2.py
module fromGitHub
bz2
might not exist if Python hasn’t been built to include it.It’s definitely a hack, but you could create a dummy empty
bz2.py
in your working directory, and hope Pandas doesn’t need to access any attributes from it at import time.