Confused about the package_dir and packages settings in setup.py

Steve Sawyer picture Steve Sawyer · Jun 17, 2013 · Viewed 16.3k times · Source

Here is my project directory structure, which includes the project folder, plus a "framework" folder containing packages and modules shared amongst several projects which resides at the same level in the hierarchy as the project folders:

--------------------------------------------------------------
Framework/
    package1/
        __init__.py
        mod1.py
        mod2.py
    package2/
        __init__.py
        moda.py
        modb.py

My_Project/
    src/
        main_package/
             __init__.py
             main_module.py
    setup.py
    README.txt
--------------------------------------------------------------

Here is a partial listing of the contents of my setup.py file:

--------------------------------------------------------------
from distutils.core import setup

setup(packages=['package1',
        'package2.moda',
        'main_package'],
    package_dir={'package1': '../Framework/package1', 
        'package2.moda': '../Framework/package2', 
        'main_package': 'src/main_package'})

--------------------------------------------------------------

Here are the issues:

  1. No dist or build directories are created

  2. Manifest file is created, but all modules in package2 are listed, not just the "moda.py" module

  3. The build terminates with an error: README.txt: Incorrect function

I don't know if I have a single issue (possibly related to my directory struture) or if I have multiple issues but I've read everything I can find on distribution of Python applications, and I'm stumped.

Answer

Éric Araujo picture Éric Araujo · Jun 18, 2013

If I understand correctly, the paths in package_dir should stop at the parent directory of the directories which are Python packages. In other words, try this:

package_dir={'package1': '../Framework', 
             'package2': '../Framework', 
             'main_package': 'src'})