Python setup.py包和unicode_文本
我已经在Py2.7中创建了一个包,并试图使其与Py3兼容。 问题是如果我在Python setup.py包和unicode_文本,python,packaging,setup.py,pypi,Python,Packaging,Setup.py,Pypi,我已经在Py2.7中创建了一个包,并试图使其与Py3兼容。 问题是如果我在 __init__.py 导入生成将返回此错误 error in daysgrounded setup command: package_data must be a dictionary mapping package names to lists of wildcard patterns 我读过政治公众人物,但我不明白这和像这样的口授有什么关系 __pkgdata__ 有人能帮忙吗 __init__.py #!/
__init__.py
导入生成将返回此错误
error in daysgrounded setup command: package_data must be a dictionary mapping
package names to lists of wildcard patterns
我读过政治公众人物,但我不明白这和像这样的口授有什么关系
__pkgdata__
有人能帮忙吗
__init__.py
#!/usr/bin/env python
# -*- coding: latin-1 -*-
"""Manage child(s) grounded days."""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
# ToDo: correct why the above unicode_literals import prevents setup.py from working
import sys
from os import path
sys.path.insert(1, path.dirname(__file__))
__all__ = ['__title__', '__version__',
'__desc__', '__license__', '__url__',
'__author__', '__email__',
'__copyright__',
'__keywords__', '__classifiers__',
#'__packages__',
'__entrypoints__', '__pkgdata__']
__title__ = 'daysgrounded'
__version__ = '0.0.9'
__desc__ = __doc__.strip()
__license__ = 'GNU General Public License v2 or later (GPLv2+)'
__url__ = 'https://github.com/jcrmatos/DaysGrounded'
__author__ = 'Joao Matos'
__email__ = 'jcrmatos@gmail.com'
__copyright__ = 'Copyright 2014 Joao Matos'
__keywords__ = 'days grounded'
__classifiers__ = [# Use below to prevent any unwanted publishing
#'Private :: Do Not Upload'
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Win32 (MS Windows)',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
'Natural Language :: English',
'Natural Language :: Portuguese',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Topic :: Other/Nonlisted Topic']
#__packages__ = ['daysgrounded']
__entrypoints__ = {
'console_scripts': ['daysgrounded = daysgrounded.__main__:main'],
#'gui_scripts': ['app_gui = daysgrounded.daysgrounded:start']
}
__pkgdata__ = {'daysgrounded': ['*.txt']}
#__pkgdata__= {'': ['*.txt'], 'daysgrounded': ['*.txt']}
setup.py
#!/usr/bin/env python
# -*- coding: latin-1 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from setuptools import setup, find_packages
#import py2exe
#from daysgrounded import *
from daysgrounded import (__title__, __version__,
__desc__, __license__, __url__,
__author__, __email__,
__keywords__, __classifiers__,
#__packages__,
__entrypoints__, __pkgdata__)
setup(
name=__title__,
version=__version__,
description=__desc__,
long_description=open('README.txt').read(),
#long_description=(read('README.txt') + '\n\n' +
# read('CHANGES.txt') + '\n\n' +
# read('AUTHORS.txt')),
license=__license__,
url=__url__,
author=__author__,
author_email=__email__,
keywords=__keywords__,
classifiers=__classifiers__,
packages=find_packages(exclude=['tests*']),
#packages=__packages__,
entry_points=__entrypoints__,
install_requires=open('requirements.txt').read(),
#install_requires=open('requirements.txt').read().splitlines(),
include_package_data=True,
package_data=__pkgdata__,
#console=['daysgrounded\\__main__.py']
)
谢谢
JM对输入文件中的每个字符串文本使用
unicode\u文本
与使用u'…'
相同,这意味着在\u init\uuuuuuuuuy.py
中
__pkgdata__ = {'daysgrounded': ['*.txt']}
实际上和
__pkgdata__ = {u'daysgrounded': [u'*.txt']}
对于python2,setuptools在这里不需要unicode
,而是str
,因此它失败了
由于在
\uuu init\uuuu.py
中似乎没有在字符串文本中使用任何unicode字符,所以只需使用普通ascii,因此您可以简单地删除unicode\u文本导入。如果您确实在文件中的某个位置使用了unicode文本,而您的帖子中没有显示,请在该位置使用显式unicode文本。这是setuptools中的一个错误。它使用isinstance(k,str)
验证值,当字符串通过unicode\u文本导入转换为2.xunicode
类时,验证失败。应该对其进行修补以使用isinstance(k,basestring)
最简单的解决方案是将配置设置直接放入setup.py
中,而不是将它们存储在中。如果您需要对\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
从setuptools dist.py:
def检查包数据(dist、attr、value):
“”“验证值是否是全局列表的包名称字典”“”
如果isinstance(值,dict):
对于k,v,在value.items()中:
如果不存在(k,str):中断
尝试:国际热核实验堆(五)
除类型错误外:
打破
其他:
返回
raise DISTUTILSSETUP错误(
attr+“必须是一个字典,将包名称映射到”
“通配符模式”
)
的用法是使Python 2与Python 3代码兼容,其中str
现在是Python 2中的unicode字符串与字节字符串。它可以很好地防止字节字符串和unicode字符串的混合,这是Py2上的一个长期问题,但是也有一些类似的问题
已经解释了错误,我想说对于setup.py
它不是严格要求的,而且修复它有点难看,特别是当您有大量包\u数据的条目时
如果要在setup.py中保留unicode\u literals
,只需将dict
键编码为字节字符串:
__pkgdata__ = {b'daysgrounded': ['*.txt']}
但是,在Python 3下,它将失败并显示相同的消息,因此需要涵盖两个版本:
if sys.version_info.major == 2:
__pkgdata__ = {b'daysgrounded': ['*.txt']}
else:
__pkgdata__ = {'daysgrounded': ['*.txt']}
或者使用模块中的bytes\u到\u native\u str
:
“这是setuptools中的一个bug”:您知道是否存在bug报告吗?
from future.utils import bytes_to_native_str
__pkgdata__ = {bytes_to_native_str(b'daysgrounded'): ['*.txt']}