Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

python - Setting up setup.py for packaging of a single .py file and a single data file without needing to create any folders

Project tree:

$.
├── happy_birthday-art.txt
├── happy_birthday.py
├── MANIFEST.in
├── README.rst
└── setup.py

setup.py

from setuptools import setup

setup(
    name='Happy_birthday',
    py_modules=['happy_birthday'],
    data_files=['happy_birthday-art.txt'],
    entry_points={
    'console_scripts': ['happy_birthday = happy_birthday:main', ],},
    long_description=open('README.rst').read(),
)

Now when I do python setup.py sdist and then pip install the created .tar.gz file in a virtual environment I get the following message:

warning: install_data: setup script did not provide a directory for 'happy-birthday-art.txt' -- installing right in '/home/username/.virtualenvs/happy_birthday'

The program uses that .txt file so it fails when trying to run it afterwards.

But I don't want to install happy_birthday-art.txt into a separate folder. I want to install it in the folder where happy_birthday.py is installed. Also, I don't want to have to use absolute paths in setup.py. How do I best set up my setup.py file?

question from:https://stackoverflow.com/questions/12461603/setting-up-setup-py-for-packaging-of-a-single-py-file-and-a-single-data-file-wi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have a single-file module like this, no folder will be created, your .py file will be moved directly into the directory which contains the other python modules (/usr/lib/pythonX.X/site-packages/, for example). That's why you have to create a directory:

$ .
|-- happy_birthday/
    |-- __init__.py
    |-- art.txt
|-- MANIFEST.in
|-- README.rst
|-- setup.py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...