我正在尝试通过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 pypitar存档是正确创建的(它包含静态文件夹),当我从PyPi下载这个相同的存档时,它也包含静态文件夹。但是,用pip安装它只会让我在我的站点内的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.py行。
我在运行python setup.py sdist upload -r pypitest时会收到这个警告
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data'
发布于 2015-03-14 12:20:24
带远程的解决方案
# 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={.}行,则不需要它们。
使用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比远程工具具有更多的功能。
https://stackoverflow.com/questions/29018635
复制相似问题