如何修复 Python ValueError:bad marshal data?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30861493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 09:05:58  来源:igfitidea点击:

How to fix Python ValueError:bad marshal data?

python

提问by Jaime M.

Running flexget Python script in Ubuntu, I get an error:

在 Ubuntu 中运行 flexget Python 脚本,出现错误:

$ flexget series forget "Orange is the new black" s03e01
Traceback (most recent call last):
File "/usr/local/bin/flexget", line 7, in <module>
from flexget import main
File "/usr/local/lib/python2.7/dist-packages/flexget/__init__.py", line 11, in <module>
from flexget.manager import Manager
File "/usr/local/lib/python2.7/dist-packages/flexget/manager.py", line 21, in <module>
from sqlalchemy.ext.declarative import declarative_base
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/__init__.py", line 8, in <module>
from .api import declarative_base, synonym_for, comparable_using, \
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/api.py", line 11, in <module>
from ...orm import synonym as _orm_synonym, \
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/__init__.py", line 17, in <module>
from .mapper import (
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 27, in <module>
from . import properties
ValueError: bad marshal data (unknown type code)

采纳答案by Jaime M.

If you get that error, the compiled version of the Python module (the .pyc file) is corrupt probably. Gentoo Linux provides python-updater, but in Debian the easier way to fix: just delete the .pyc file. If you don't know the pyc, just delete all of them (as root):

如果出现该错误,则 Python 模块(.pyc 文件)的编译版本可能已损坏。Gentoo Linux 提供了python-updater,但在 Debian 中更容易修复:只需删除 .pyc 文件。如果您不知道 pyc,只需删除所有这些(以 root 身份):

find /usr -name '*.pyc' -delete

回答by Anthon

Just delete

删除即可

/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/properties.pyc

it is corrupt as the text indicates. You'll probably have to do so as root.

正如文本所示,它已损坏。您可能必须这样做root

After that start (again as root) run python (2.7):

启动后(再次以 root 身份)运行 python (2.7):

/usr/bin/python -c "import sqlalchemy.orm.properties"

to recreate this .pycfile.

重新创建此.pyc文件。

If you don't recreate the .pycfile, your program starts slower than necessary as the .pyfile takes longer to load than the .pyc(and a normal user cannot write the .pycfile).

如果您不重新创建.pyc文件,您的程序启动速度会比所需的慢,因为.py加载文件所需的时间比加载文件的时间长.pyc(并且普通用户无法写入.pyc文件)。

回答by Ewan Mellor

This can happen if you have Python 2.7 .pyc files and you try to load them using Python 3.5. In my case this was a third-party tarball that erroneously included pre-compiled Python 2.7 .pyc files along with the source code.

如果您有 Python 2.7 .pyc 文件并尝试使用 Python 3.5 加载它们,就会发生这种情况。就我而言,这是一个第三方 tarball,它错误地包含预编译的 Python 2.7 .pyc 文件以及源代码。

回答by Michael Redman

I resolved a similar error by un-installing and re-installing the Python application I was using, and all dependencies, using the system package manager.

我通过使用系统包管理器卸载并重新安装我正在使用的 Python 应用程序和所有依赖项解决了类似的错误。

In my case I was using awscli on Debian 9 and the error was "ValueError: bad marshal data (set size out of range)".

就我而言,我在 Debian 9 上使用 awscli,错误是“ValueError: bad marshal data (set size out of range)”。

I ran as root:

我以 root 身份运行:

apt-get purge awscli
apt-get autoremove
apt-get install awscli

And then the error was fixed.

然后错误被修复了。

I could imagine cases where the broken package might not get removed (for example because it was marked as manually installed, or was a dependency of another application still installed), in those cases this action may not resolve the error. However I thought I should try this way before manually deleting .pyc files the system installed, and I got lucky.

我可以想象损坏的包可能不会被删除的情况(例如,因为它被标记为手动安装,或者仍然是另一个应用程序的依赖项),在这些情况下,此操作可能无法解决错误。但是我想我应该在手动删除系统安装的 .pyc 文件之前尝试这种方式,我很幸运。

回答by tgoodhart

There also appears to have been some sort of regression in setuptools with use with python 3.7. See for an example - https://github.com/pypa/setuptools/issues/1257

在与 python 3.7 一起使用的 setuptools 中似乎也有某种回归。参见示例 - https://github.com/pypa/setuptools/issues/1257

Forcing reinstallation of setuptools fixed this issue for me.

强制重新安装 setuptools 为我解决了这个问题。

sudo pip3 install --upgrade --force-reinstall setuptools

回答by cosmos3298

I also got this problem in Windows environment(win 10).

我在 Windows 环境(win 10)中也遇到了这个问题。

I fixed it by going to the Settings and repairing Python 3.7 with its installer. Everything works fine since then.

我通过转到设置并使用其安装程序修复 Python 3.7 来修复它。从那以后一切正常。

As far as I could recall, I had kept a dash server running when my computer went to hibernation. Maybe the damage was done in the hibernating process somehow.

据我所知,当我的计算机进入休眠状态时,我一直在运行一个dash服务器。也许损坏是在休眠过程中以某种方式造成的。

回答by Jim Chen

I solved this problem by the following procedure :

我通过以下程序解决了这个问题:

In the error code message, you can see from sqlalchemy.ext.declarative import declarative_basecause this error.

在错误代码消息中,您可以看到 from sqlalchemy.ext.declarative import declarative_base导致此错误的原因。

So just pip uninstall sqlalchemyand pip install sqlalchemy, problem solved.

所以刚刚pip uninstall sqlalchemypip install sqlalchemy,问题解决了。