'sdist correct but pip install no stati' 程序分发正确,但pip安装无状态

2024-04-19 13:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过pip(存储在Pypi上)来交付Django应用程序。 问题是,当我用pip安装应用程序时,它不包含主指定包中的静态文件夹。在

以下是我所拥有的:

├── LICENSE.txt
├── MANIFEST.in
├── README.rst
├── setup.cfg
├── setup.py
└── zxcvbn_password
    ├── fields.py
    ├── __init__.py
    ├── static
    │   └── zxcvbn_password
    │       └── js
    │           ├── password_strength.js
    │           ├── zxcvbn-async.js
    │           └── zxcvbn.js
    ├── validators.py
    └── widgets.py

我要做的是:

^{pr2}$

tar归档文件创建正确(它包含静态文件夹),当我从PyPi下载这个相同的归档文件时,它也包含静态文件夹。但是用pip安装它只会让我在我的站点包中得到zxcvbn_password中的以下内容:

└── zxcvbn_password
    ├── fields.py
    ├── __init__.py
    ├── validators.py
    └── widgets.py

我就是这样写我的设置.py公司名称:

from distutils.core import setup

setup(
    name='django-zxcvbn-password',
    packages=['zxcvbn_password'],
    include_package_data=True,
    url='https://github.com/Pawamoy/django-zxcvbn-password',
    # and other data ...
)

还有我的清单.in公司名称:

include LICENSE.txt
include README.rst
recursive-include zxcvbn_password/static *

我做错什么了吗? 为什么pip使用setup.py install时没有安装静态文件夹?在

编辑

我加了一行设置.py从distutils导入设置函数。
我在运行python setup.py sdist upload -r pypitest时收到此警告:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'


Tags: pipinpytxt文件夹应用程序datainclude
1条回答
网友
1楼 · 发布于 2024-04-19 13:17:04

Distutils溶液

# MANIFEST.in

include LICENSE.txt
include README.rst
# recursive-include zxcvbn_password/static *

以及

^{pr2}$

我从中注释掉了递归include行清单.in并且include_package_data=True来自设置.py:显然,如果指定了package\u data={…}行,则不需要它们设置.py. 在

使用Setuptools的解决方案

# MANIFEST.in

include LICENSE.txt
include README.rst
recursive-include zxcvbn_password/static *

以及

# setup.py

from setuptools import setup

setup(
    name='django-zxcvbn-password',
    packages=['zxcvbn_password'],
    include_package_data=True,
    url='https://github.com/Pawamoy/django-zxcvbn-password',
    # and other data ...
)

唯一更改的行是from setuptools import setup。在

结论

我的问题确实来自于我导入设置函数的方式。 阅读本文:Differences between distribute, distutils, setuptools and distutils2?,我了解到Setuptools比Distutils具有更多的功能。在

相关问题 更多 >