pythonsetup.pyegg

Creating an egg file generates only EGG-INFO folder


I have a python file named file_processor.py. I would like to create an egg file out of this python file to use it in another projects. My setup.py file looks as following:

from setuptools import setup, find_packages

setup(
    name = "file_processor",
    version = "0.5",
    packages = find_packages()
)

And I run this script with the following command:

python setup.py bdist_egg

This command generates 3 folders, namely: build, dist, file_processor.egg-info. My .egg file is located in the dist folder. However, if I change its extension from .egg to .zip to see the contents, I find only one folder which is EGG-INFO, and not the actual python file. An so, if I try to add that .egg file into my project path and import file_processor module, python throws an error that no module named file_processor found. What am I doing wrong here? Note: I got the information for generating egg files from this link


Solution

  • Wheel files are generally preferred over eggs these days.

    Regardless, I would guess that you don't have the file_processor.py in a separate directory and you have it in the same directory as the setup.py, it needs to be in it's own directory.

    You should also include a __init__.py in that directory, inside the file you can put

    from .file_processor import *

    This will import all the functions from your file into the package so you can use them.

    This tutorial is quite good if you're looking for more information https://python-packaging.readthedocs.io/en/latest/minimal.html