在 MacOS 上安装我的 python 包会出现 bad marshall data 错误

Installing my python package on MacOS gives bad marshall data error

在 Mac OS.

上安装我自己创建的 python 包时,我遇到了下面提到的错误编组数据错误
deveshs-MacBook-Pro:mycli devesh$ sudo python setup-4.0.py install 
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
/usr/bin/python -E -c pass
TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing requirements to mycli.egg-info/requires.txt
writing cftcli.egg-info/PKG-INFO
writing top-level names to mycli.egg-info/top_level.txt
writing dependency_links to mycli.egg-info/dependency_links.txt
writing entry points to mycli.egg-info/entry_points.txt
reading manifest file 'mycli.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mycli.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.10-intel/egg
running install_lib
running build_py
copying mycli.egg-info/PKG-INFO -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying mycli.egg-info/SOURCES.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying mycli.egg-info/dependency_links.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying mycli.egg-info/entry_points.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying mycli.egg-info/requires.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying mycli.egg-info/top_level.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
Traceback (most recent call last):
  File "setup-4.0.py", line 42, in <module>
"requests==2.4.3",
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
  File "/Library/Python/2.7/site-packages/setuptools/command/install.py", line 67, in run
self.do_egg_install()
  File "/Library/Python/2.7/site-packages/setuptools/command/install.py", line 109, in do_egg_install
self.run_command('bdist_egg')
      File         "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
  File "/Library/Python/2.7/site-packages/setuptools/command/bdist_egg.py", line 208, in run
os.path.join(archive_root, 'EGG-INFO'), self.zip_safe()
  File "/Library/Python/2.7/site-packages/setuptools/command/bdist_egg.py", line 244, in zip_safe
return analyze_egg(self.bdist_dir, self.stubs)
  File "/Library/Python/2.7/site-packages/setuptools/command/bdist_egg.py", line 354, in analyze_egg
safe = scan_module(egg_dir, base, name, stubs) and safe
  File "/Library/Python/2.7/site-packages/setuptools/command/bdist_egg.py", line 391, in scan_module
code = marshal.load(f)
ValueError: bad marshal data (unknown type code)

我尝试从 setuptools 目录中删除所有 *.pyc 文件。 请指导如何解决此问题。 谢谢

首先我认为问题出在文件名上,它应该只是 setup.py,但是 sudo python setup.py install 也给出了同样的错误。

我发现的解决方法是先创建一个 source-distribution。 see documentation here

下面的脚本可以正常工作并使我们摆脱上述问题。

cp -f setup-4.0.py setup.py
python setup.py sdist --format=zip,gztar
sudo pip install dist/mycli-4.0.tar.gz
rm setup.py 

要卸载:sudo pip uninstall mycli

希望它能帮助一些 Mac 用户。谢谢。