Philip Mutua
Philip Mutua

Reputation: 6891

EOFError: marshal data too short

Why do I get the following error when I run the django server and how do I fix it ? :

EOFError: marshal data too short

details

Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f6e5dbacea0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/aphya1/work/1-erp-project/ERP/mis/mis/urls.py", line 14, in <module>
    url(r'^hr/', include('hr.urls', namespace='hr')),
  File "/usr/local/lib/python3.5/dist-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/aphya1/work/1-erp-project/ERP/mis/hr/urls.py", line 2, in <module>
    from hr import views
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 661, in exec_module
  File "<frozen importlib._bootstrap_external>", line 765, in get_code
  File "<frozen importlib._bootstrap_external>", line 476, in _compile_bytecode
EOFError: marshal data too short

Upvotes: 18

Views: 24246

Answers (3)

Snympi
Snympi

Reputation: 968

I experienced this problem using Python in WSL2. The error message "bad marshal data (unknown type code)" usually indicates that a .pyc file is corrupted. This could happen due to an interrupted Python process, disk errors, or version mismatches between Python interpreters.

The first step as indicated before is:

find . -name "*.pyc" -type f -delete

This worked for the next time I ran the application, but as soon as I tried again, the same "bad marshal data" error would be back.

Finally, it was due to a problem with the installation of the trl package. The following steps resolved my problem:

pip uninstall trl
pip install trl

Upvotes: 1

Zohab Ali
Zohab Ali

Reputation: 9574

I delete all .pyc files using terminal and it worked for me

find . -name \*.pyc -delete

Upvotes: 18

Keshav Pradeep Ramanath
Keshav Pradeep Ramanath

Reputation: 1687

I also encountered the error:

EOFError: marshal data too short.

Even though no changes were made to any of the existing files, this error was thrown.

Some *.pyc files get created automatically which are compiled byte code of a script, which gets dynamically created when a Python script runs to speed up future launches.

I am using an Oracle VM VirtualBox manager, working on Python.

I was trying to install pyspark. The spark folder structure was something like this

spark****/python/pyspark 

Under this folder contained a folder by name '__pycache__' I went to the pyspark folder and deleted the '__pycache__' folder using the command:

rm -r __pycache__/

This eliminated the error for me and I am now able to import pyspark.

Hope this helps.

Upvotes: 21

Related Questions