python setup.py 寄存器无法解码位置 0 中的字节 0xff
python setup.py register can't decode byte 0xff in position 0
我正在打包我的 python 代码并希望上传到我的 pypi,
我的 setup.py 是这样的:
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, find_packages
import sys
setup(
name="JsonGet",
version="0.2.0",
author="Dennis Wang",
author_email="dennis.wang@detvista.com",
license="Apache License",
url="https://github.com/cortexiphan1/JsonGet",
packages=["JsonGet"],
install_requires=["simplejson"],
classifiers=[
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Text Processing :: Indexing",
"Topic :: Utilities",
"Topic :: Internet",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6"
],
)
然后我成功运行这些命令
python setup.py sdist
python setup.py install
在这些之后我可以导入我的包并制作一个测试用例。
但是当我注册并上传到pypi时,它抛出了这个解码错误,
我已经搜索并尝试了很多次,所有文件都是utf-8编码的。
当我通过 powershell 在 windows 上使用这些命令时,它抛出
'gbk'编解码器无法解码。
我不知道到底发生了什么,我第一次上传代码到pypi...
(py3) [root@detvista JsonGet]# python setup.py register sdist upload
running register
running egg_info
writing JsonGet.egg-info/PKG-INFO
writing dependency_links to JsonGet.egg-info/dependency_links.txt
writing requirements to JsonGet.egg-info/requires.txt
writing top-level names to JsonGet.egg-info/top_level.txt
reading manifest file 'JsonGet.egg-info/SOURCES.txt'
writing manifest file 'JsonGet.egg-info/SOURCES.txt'
Traceback (most recent call last):
File "setup.py", line 25, in <module>
"Programming Language :: Python :: 3.6"
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/site-packages/setuptools/command/register.py", line 10, in run
orig.register.run(self)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/command/register.py", line 45, in run
self._set_config()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/command/register.py", line 71, in _set_config
config = self._read_pypirc()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/config.py", line 57, in _read_pypirc
config.read(rc)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/configparser.py", line 697, in read
self._read(fp, filename)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/configparser.py", line 1015, in _read
for lineno, line in enumerate(fp, start=1):
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
问题似乎出在self._read_pypirc()
。也就是说,有问题的文件是您的~/.pypirc
。编辑文件并验证它采用 UTF-8 编码并且不包含字节顺序标记等过多字符。
我正在打包我的 python 代码并希望上传到我的 pypi, 我的 setup.py 是这样的:
#!/usr/bin/env python
from __future__ import print_function
from setuptools import setup, find_packages
import sys
setup(
name="JsonGet",
version="0.2.0",
author="Dennis Wang",
author_email="dennis.wang@detvista.com",
license="Apache License",
url="https://github.com/cortexiphan1/JsonGet",
packages=["JsonGet"],
install_requires=["simplejson"],
classifiers=[
"Environment :: Web Environment",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Topic :: Text Processing :: Indexing",
"Topic :: Utilities",
"Topic :: Internet",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6"
],
)
然后我成功运行这些命令
python setup.py sdist
python setup.py install
在这些之后我可以导入我的包并制作一个测试用例。
但是当我注册并上传到pypi时,它抛出了这个解码错误, 我已经搜索并尝试了很多次,所有文件都是utf-8编码的。
当我通过 powershell 在 windows 上使用这些命令时,它抛出 'gbk'编解码器无法解码。
我不知道到底发生了什么,我第一次上传代码到pypi...
(py3) [root@detvista JsonGet]# python setup.py register sdist upload
running register
running egg_info
writing JsonGet.egg-info/PKG-INFO
writing dependency_links to JsonGet.egg-info/dependency_links.txt
writing requirements to JsonGet.egg-info/requires.txt
writing top-level names to JsonGet.egg-info/top_level.txt
reading manifest file 'JsonGet.egg-info/SOURCES.txt'
writing manifest file 'JsonGet.egg-info/SOURCES.txt'
Traceback (most recent call last):
File "setup.py", line 25, in <module>
"Programming Language :: Python :: 3.6"
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/site-packages/setuptools/command/register.py", line 10, in run
orig.register.run(self)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/command/register.py", line 45, in run
self._set_config()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/command/register.py", line 71, in _set_config
config = self._read_pypirc()
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/distutils/config.py", line 57, in _read_pypirc
config.read(rc)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/configparser.py", line 697, in read
self._read(fp, filename)
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/configparser.py", line 1015, in _read
for lineno, line in enumerate(fp, start=1):
File "/home/pyadmin/anaconda3/envs/py3/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
问题似乎出在self._read_pypirc()
。也就是说,有问题的文件是您的~/.pypirc
。编辑文件并验证它采用 UTF-8 编码并且不包含字节顺序标记等过多字符。