I started using sampleproject as a skeleton for a small project of mine, I got the following error when doing python setup.py sdist
:
....
Creating tar archive
Traceback (most recent call last):
File "setup.py", line 100, in <module>
'sample=sample:main',
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 "/Users/stefaan/tmp/python-packaging-playground/sampleproject/ve/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/sdist.py", line 147, in run
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/sdist.py", line 451, in make_distribution
owner=self.owner, group=self.group)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 392, in make_archive
owner=owner, group=group)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/archive_util.py", line 237, in make_archive
filename = func(base_name, base_dir, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/archive_util.py", line 101, in make_tarball
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 1687, in open
_Stream(name, filemode, comptype, fileobj, bufsize),
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 431, in __init__
self._init_write_gz()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 459, in _init_write_gz
self.__write(self.name + NUL)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tarfile.py", line 475, in __write
self.buf += s
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
I fired up my debugger (my setup: Python 2.7.2 in a virtualenv on Mac OS X 10.8.5), and traced the issue back to find_version
in setup.py:
def find_version(*file_paths):
with codecs.open(os.path.join(here, *file_paths), 'r', 'latin1') as f:
version_file = f.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
It returns the version as a unicode string, and in the tarfile logic this unicode string is added to a raw string, resulting in the UnicodeDecodeError: 'ascii' codec can't decode
issue .
return str(version_match.group(1))
# or
return version_match.group(1).encode('ascii')