我正在尝试通过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
我所做的是以下内容:
python setup.py register -r pypi
python setup.py sdist upload -r pypi
正确创建了tar存档(它包含静态文件夹),当我从PyPi下载相同的存档时,它还包含静态文件夹。但是用pip安装它只是在我的site-packages中的zxcvbn_password
中给出了以下内容:
└── zxcvbn_password
├── fields.py
├── __init__.py
├── validators.py
└── widgets.py
这就是我编写setup.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 ...
)
我的MANIFEST.in:
include LICENSE.txt
include README.rst
recursive-include zxcvbn_password/static *
我做错了吗?
为什么pip使用setup.py install
?
我添加了从distutils导入setup函数的setup.py行
运行python setup.py sdist upload -r pypitest
时,我收到此警告:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'
答案 0 :(得分:0)
# MANIFEST.in
include LICENSE.txt
include README.rst
# recursive-include zxcvbn_password/static *
和
# setup.py
from distutils.core import setup
setup(
name='django-zxcvbn-password',
packages=['zxcvbn_password'],
package_data={'': ['static/zxcvbn_password/js/*.js']},
# include_package_data=True,
url='https://github.com/Pawamoy/django-zxcvbn-password',
# and other data ...
)
我注释掉了MANIFEST.in中的递归包含行和来自setup.py的include_package_data = True:显然,如果在setup.py中指定package_data = {...}行,则不需要它们。
# 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具有更多功能。