I have written an application with python (2.7). The structure looks like:
kent$ tree myApp
myApp
|-- foo.py
|-- gui
| |-- g1.py
| |-- g2.py
| |-- g3.py
| `-- __init__.py
|-- icons
| |-- a.png
| `-- e.png
|-- logic
| |-- __init__.py
| |-- l1
| | |-- __init__.py
| | |-- la.py
| | `-- lc.py
| |-- l2
| | |-- __init__.py
| | |-- ld.py
| | `-- lf.py
| |-- logic1.py
| |-- logic2.py
| `-- logic3.py
|-- myApp.py
`-- resources
|-- x.data
`-- z.data
Now I am about to write a setup.py
to distribute my application. I am new to this. After reading the py doc and doing some testing. a few questions come up:
how can I (or should I) package my root package (myApp) under /lib/python/site-package
?
since in my py file, I reference resources/icons by relative path. for example, in foo.py
there could be icons/a.png
and in gui/g1.py
there could be ../icons/e.png
and so on
how can I package icons
and resources
directory?
It seems that package_data
and data_files
won't copy the two directories to right place.
is this the right way?
packages = [''],
package_dir = {'': ''},
package_data= {'': ['icons/*.*', 'resources/*.*']},
after install, my files will be:
/usr/lib/python2.7/site-packages/icons/*.png
/usr/lib/python2.7/site-packages/resources/*.data
/usr/lib/python2.7/site-packages/gui/...
/usr/lib/python2.7/site-packages/logic/...
Is there problem of my application structure?
should those resources/icons/whatever files go to certain python package, not under the project root? so that in setup.py I can use package_data
to copy them to right place.
The setup.py file is a Python file which indicates that the installation module/package is most likely packed and distributed using Distutils, the Python Module distribution standard.
setup(name="my_package_name", python_requires='>3.5. 2', [...] Save this answer.
The short answer is that requirements. txt is for listing package requirements only. setup.py on the other hand is more like an installation script. If you don't plan on installing the python code, typically you would only need requirements.
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup
setup(name="somename",
version="1.0",
description="description string",
long_description="""\
long description
""",
author="Foo",
author_email="[email protected]",
url="http://nowhere.com",
include_package_data=True,
license="MIT",
packages=["gui", "logic"],
package_dir={
"gui": "myApp/gui",
"logic": "myApp/logic",
},
classifiers=[
"Development Status :: 5 - Production/Stable",
"Topic :: Utilities",
"License :: OSI Approved :: MIT License"
],
data_files=[
('/path/to/resources', ['resources/x.data', 'resources/y.data']),
('/path/to/icons', ['myApp/icons/a.ico', 'myApp/icons/e.ico'])
]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With