pandas実行時に「ModuleNotFoundError: No module named ‘_bz2’」
今回はpandas実行時に下記のようなエラーが起きてしまったときの対処法についてご紹介していこうと思います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
Traceback (most recent call last): File "/opt/python3/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/opt/python3/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/python3/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/opt/python3/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "/opt/python3/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check all_issues = checks.run_checks( File "/opt/python3/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "/opt/python3/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/opt/python3/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/opt/python3/lib/python3.8/site-packages/django/urls/resolvers.py", line 416, in check for pattern in self.url_patterns: File "/opt/python3/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/opt/python3/lib/python3.8/site-packages/django/urls/resolvers.py", line 602, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/opt/python3/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/opt/python3/lib/python3.8/site-packages/django/urls/resolvers.py", line 595, in urlconf_module return import_module(self.urlconf_name) File "/opt/python3/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 843, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/server/config/urls.py", line 24, in <module> from staff.companies import urls as companies_urls File "/server/staff/companies/urls.py", line 5, in <module> from .views import CompanyList File "/server/staff/companies/views.py", line 18, in <module> import pandas as pd File "/opt/python3/lib/python3.8/site-packages/pandas/__init__.py", line 48, in <module> from pandas.core.api import ( File "/opt/python3/lib/python3.8/site-packages/pandas/core/api.py", line 47, in <module> from pandas.core.groupby import ( File "/opt/python3/lib/python3.8/site-packages/pandas/core/groupby/__init__.py", line 1, in <module> from pandas.core.groupby.generic import ( File "/opt/python3/lib/python3.8/site-packages/pandas/core/groupby/generic.py", line 76, in <module> from pandas.core.frame import DataFrame File "/opt/python3/lib/python3.8/site-packages/pandas/core/frame.py", line 171, in <module> from pandas.core.generic import NDFrame File "/opt/python3/lib/python3.8/site-packages/pandas/core/generic.py", line 147, in <module> from pandas.core.describe import describe_ndframe File "/opt/python3/lib/python3.8/site-packages/pandas/core/describe.py", line 45, in <module> from pandas.io.formats.format import format_percentiles File "/opt/python3/lib/python3.8/site-packages/pandas/io/formats/format.py", line 105, in <module> from pandas.io.common import ( File "/opt/python3/lib/python3.8/site-packages/pandas/io/common.py", line 8, in <module> import bz2 File "/opt/python3/lib/python3.8/bz2.py", line 19, in <module> from _bz2 import BZ2Compressor, BZ2Decompressor ModuleNotFoundError: No module named '_bz2' |
pandasのバージョンは1.5.2で、3.2.16のDjangoを使用してpython manage.py runserverをすると上記のエラーが出ました。
OSはRHEL系のLinuxディストリビューションであるAlmaLinux9.3を使っている状態です。
pandas実行時に「ModuleNotFoundError: No module named '_bz2’」
結論から言うと、下記のコマンドでbzip2-develをインストールしてからPythonを改めて入れ直すとエラーが出なくなるでしょう。
1 |
dnf install bzip2-devel -y |
Pythonを入れ直すのは大変ですが頑張りましょう。
終わりに
今回はpandas実行時に表題のようなエラーが起きてしまったときの対処法についてご紹介いたしました。
ディスカッション
コメント一覧
まだ、コメントがありません