Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: simple example for a python egg with a one-file source file?

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....

like image 603
Jason S Avatar asked May 17 '10 20:05

Jason S


People also ask

How do I make a Python egg 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.

What is a Python egg file?

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.

How do I run a .EGG file?

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.


1 Answers

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

like image 129
Gary van der Merwe Avatar answered Oct 17 '22 04:10

Gary van der Merwe