setuptools / distribute에 패키지 데이터를 포함시키는 방법은 무엇입니까?
setuptools / distribute를 사용할 때 설치 프로그램이 package_data
파일 을 가져올 수 없습니다 . 내가 읽은 모든 것은 다음이 올바른 방법이라고 말합니다. 누군가 조언 해 줄 수 있습니까?
setup(
name='myapp',
packages=find_packages(),
package_data={
'myapp': ['data/*.txt'],
},
include_package_data=True,
zip_safe=False,
install_requires=['distribute'],
)
myapp/data/
데이터 파일의 위치는 어디 입니까?
나는 이것이 오래된 질문이라는 것을 알고 있지만 사람들이 Google을 통해 자신의 길을 찾는 경우 : package_data
낮고 더러운 거짓말 입니다. 바이너리 패키지 ( python setup.py bdist ...
)를 빌드 할 때만 사용되며 소스 패키지 ( )를 빌드 할 때는 사용 되지 않습니다python setup.py sdist ...
. 물론 이것은 우스운 일입니다. 소스 배포판을 만들면 이진 배포판을 빌드하기 위해 다른 사람에게 파일 모음을 보낼 수 있습니다.
어쨌든 사용 MANIFEST.in
은 바이너리 배포와 소스 배포 모두 에서 작동 합니다 .
방금이 같은 문제가있었습니다. 해결책은 단순히 제거하는 것이 었습니다 include_package_data=True
.
여기서 읽은 후에 는 이름에서 알 수 있듯이 "패키지 데이터 포함"과 달리 버전 제어의include_package_data
파일을 포함 하는 것을 목표로 삼았습니다. 문서에서 :
include_package_data의 데이터 파일은 CVS 또는 Subversion 제어에 있어야합니다.
...
포함 된 파일을보다 세밀하게 제어하려면 (예를 들어, 패키지 디렉토리에 문서 파일이 있고 설치에서 제외하려는 경우)
package_data
키워드 를 사용할 수도 있습니다 .
그 주장을 꺼내는 것은 그것을 고쳤습니다. 우연히도 distutils로 바꾸었을 때도 그 주장을 받아들이지 않기 때문에 그것이 효과가 있었던 이유입니다.
@Joe의 권고에 따라 include_package_data=True
라인 을 제거하는 것도 나에게 효과적 이었습니다.
좀 더 자세히 설명하기 위해 파일 이 없습니다 MANIFEST.in
. CVS가 아닌 Git을 사용합니다.
리포지토리는 다음과 같은 형태를 취합니다.
/myrepo
- .git/
- setup.py
- myproject
- __init__.py
- some_mod
- __init__.py
- animals.py
- rocks.py
- config
- __init__.py
- settings.py
- other_settings.special
- cool.huh
- other_settings.xml
- words
- __init__.py
word_set.txt
setup.py
:
from setuptools import setup, find_packages
import os.path
setup (
name='myproject',
version = "4.19",
packages = find_packages(),
# package_dir={'mypkg': 'src/mypkg'}, # didnt use this.
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.xml', '*.special', '*.huh'],
},
#
# Oddly enough, include_package_data=True prevented package_data from working.
# include_package_data=True, # Commented out.
data_files=[
# ('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
('/opt/local/myproject/etc', ['myproject/config/settings.py', 'myproject/config/other_settings.special']),
('/opt/local/myproject/etc', [os.path.join('myproject/config', 'cool.huh')]),
#
('/opt/local/myproject/etc', [os.path.join('myproject/config', 'other_settings.xml')]),
('/opt/local/myproject/data', [os.path.join('myproject/words', 'word_set.txt')]),
],
install_requires=[ 'jsonschema',
'logging', ],
entry_points = {
'console_scripts': [
# Blah...
], },
)
python setup.py sdist
소스 배포를 위해 실행 합니다 (바이너리를 시도하지 않았습니다).
그리고 새로운 가상 환경 내부에 myproject-4.19.tar.gz
, 파일이 있고
(venv) pip install ~/myproject-4.19.tar.gz
...
그리고 내 가상 환경에 설치되는 모든 것 외에도 site-packages
이러한 특수 데이터 파일이 /opt/local/myproject/data
및에 설치됩니다 /opt/local/myproject/etc
.
include_package_data=True
나를 위해 일했다.
If you use git, remember to include setuptools-git
in install_requires
. Far less boring than having a Manifest
or including all path in package_data
( in my case it's a django app with all kind of statics )
( pasted the comment I made, as k3-rnc mentioned it's actually helpful as is )
Update: This answer is old and the information is no longer valid. All setup.py configs should use import setuptools
. I've added a more complete answer at https://stackoverflow.com/a/49501350/64313
I solved this by switching to distutils. Looks like distribute is deprecated and/or broken.
from distutils.core import setup
setup(
name='myapp',
packages=['myapp'],
package_data={
'myapp': ['data/*.txt'],
},
)
Ancient question and yet... package management of python really leaves a lot to be desired. So I had the use case of installing using pip locally to a specified directory and was surprised both package_data and data_files paths did not work out. I was not keen on adding yet another file to the repo so I ended up leveraging data_files and setup.py option --install-data; something like this
pip install . --install-option="--install-data=$PWD/package" -t package
Moving the folder containing the package data into to module folder solved the problem for me.
See this question: MANIFEST.in ignored on "python setup.py install" - no data files installed?
I had the same problem these couple of days but even this thread wasn't able to be clear for me. Everything is just confusing. So i made my research and found a solution. Basically in this case here this is what you should do:
from setuptools import setup
setup(
name='myapp',
packages=['myapp'],
package_dir={'myapp':'myapp'}, # the one line where all the magic happens
package_data={
'myapp': ['data/*.txt'],
},
)
The full other stackoverflow answer here
참고URL : https://stackoverflow.com/questions/7522250/how-to-include-package-data-with-setuptools-distribute
'program tip' 카테고리의 다른 글
Rails에서 다른 형식의 일부를 어떻게 렌더링합니까? (0) | 2020.07.26 |
---|---|
쉘 스크립트의 연관 배열 (0) | 2020.07.26 |
페이드 효과가있는 요소 추가 [jQuery] (0) | 2020.07.26 |
문자열 리소스의 HTML? (0) | 2020.07.26 |
스칼라에서 배열 초기화 (0) | 2020.07.26 |