39

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 structure) or if I have multiple issues but I've read everything I can find on distribution of Python applications, and I'm stumped.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Steve Sawyer
  • 1,785
  • 4
  • 18
  • 21
  • FTR distributing only a submodule from a package (package2.moda) is not a feature supported by any packaging tool I know, and it will also cause import trouble at run-time. – merwok Dec 17 '19 at 17:43

2 Answers2

14

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'})
Neuron
  • 5,141
  • 5
  • 38
  • 59
merwok
  • 6,779
  • 1
  • 28
  • 42
  • 1
    It seems that I have to specify it as {'package1': '../Framework/package1', 'package2': '../Framework/package2'} Otherwise I get errors complaining that there is no __init__.py file found. I also keep getting an error as stated above - the output ends with error: My_Project-1.0\README.txt: Incorrect function If I remove the README.txt file, I get a warning that it's missing, but still get an error: error: My_Project-1.0\Setup.py: Incorrect function – Steve Sawyer Jun 19 '13 at 19:24
  • With this `package_dir`, should you execute `import package1` and `package2`? – ssoto Dec 17 '19 at 11:00
  • Yes, that’s the goal. – merwok Dec 17 '19 at 17:41
  • @SteveSawyer Were you able to solve this issue? I am in a similar boat. Thanks – philomath Apr 08 '21 at 00:34
7

I've had a similar problem, which was solved through the specification of the root folder and of the packages inside that root.

My package has the following structure:

.
├── LICENSE
├── README.md
├── setup.py
└── src
    └── common
        ├── __init__.py
        ├── persistence.py
        ├── schemas.py
        └── utils.py

The setup.py contains the package_dir and packages line:

package_dir={"myutils": "src"},
packages=['myutils.common'],

After running the python setup.py bdist_wheel and installing the .whl file, the package can be called using:

import myutils.common
Alan CN
  • 1,467
  • 1
  • 13
  • 13