python - setup.py 包和 unicode_literals

标签 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

我读过 PEP,但我不明白它与像这样的字典有什么关系

__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_literals 与对输入文件中的每个字符串文字使用 u'...' 相同,这意味着在您的 __init__.py 指定

__pkgdata__ = {'daysgrounded': ['*.txt']}

其实和

是一样的
__pkgdata__ = {u'daysgrounded': [u'*.txt']}

对于 python2,setuptools 在这里不期望 unicode 而是 str,所以它失败了。

因为看起来你在 __init__.py 中的字符串文字中没有使用任何 unicode 字符,只是简单的 ascii,所以你可以简单地删除 unicode_literals 导入.如果您真的在文件中的某个地方使用了 unicode 文字,但您的帖子中没有显示,请在那里使用明确的 unicode 文字。

关于python - setup.py 包和 unicode_literals,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23174738/

相关文章:

python - App Engine - 将来自 API 的响应保存在数据存储中作为文件 (blob)

python - 如何使用 Python Boto3 根据带有通配符的前缀列出对象?

python - 安排任务每 n 秒运行一次,从特定时间开始

debian - 如何将cassandra源码打包成debian包?

python - 使用setup.py安装后导入python包,而不需要重新启动?

python - 创建独立的轮子

python - 多处理只能加入一个启动的进程

java - 如何使用 maven package 命令制作 zip 存档时添加其他目录?

python - 在 Linux 上为 Kivy 游戏的每个支持平台创建安装程序或可执行文件

python - 为什么我用setup.py安装ansible找不到?