I'm not quite sure how to build a really simple one-file source module. Is there a sample module out there one the web somewhere which can be built as a python .egg?
From the setuptools page it looks pretty simple, you just have your setup.py
file and then at least one other .py file somewhere, and I can build an .egg file OK, and even install it using easy_install
, but I can't seem to import
the file from within python. (note: using 2.6.4)
here's my sample dir:
sconsconfig
setup.py
sconsconfig.py
setup.py:
from setuptools import setup, find_packages
setup(name='sconsconfig',
version='0.1',
packages = find_packages(),
)
sconsconfig.py:
def blarg(x):
return x+1
If I run setup.py bdist_egg
it then creates an egg file, but if I look in it, there's no .py source file....
Egg files are just zip files so you might be able to add __main__.py to your egg with a zip tool and make it executable in python 2.6 and run it like python myapp. egg instead of the above incantation where the PYTHONPATH environment variable is set.
Python eggs are an older distribution format for Python. The new format is called a Python wheel, which we will look at in the next chapter. An egg file is basically a zip file with a different extension. Python can import directly from an egg. You will need the SetupTools package to work with eggs.
A python egg is a "a single-file importable distribution format". Which is typically a python package. You can import the package in the egg as long as you know it's name and it's in your path. You can execute a package using the "-m" option and the package name.
You can use the py_modules
argument instead of the packages
argument to list single file modules.
See https://docs.python.org/3/distutils/setupscript.html#listing-individual-modules
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