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

2

13

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

Clermontferrand answered 17/5, 2010 at 20:16 Comment(1)
Maybe you can check this very simple exampleMarylynnmarylynne
R
7

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

Rousseau answered 5/12, 2014 at 10:50 Comment(0)
G
0

For distutils, from https://docs.python.org/3/distutils/introduction.html#a-simple-example :

from distutils.core import setup
setup(name='foo',
      version='1.0',
      py_modules=['foo'],
      )

Then you only need a file:

foo.py

And in Ubuntu 14.04:

sudo python setup.py

puts it under:

/usr/local/lib/python2.7/dist-packages/foo.py

without any directories.

Goldshell answered 27/4, 2017 at 7:56 Comment(2)
It says "error: no commands supplied". I had to do "from setuptools import setup" and "python setup.py bdist_egg"Rhatany
@Rhatany thanks for the report. I don't have time to reproduce right now, let me know if you find something out! I should have made a minimal runnable example.Goldshell

© 2022 - 2024 — McMap. All rights reserved.