Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused about the package_dir and packages settings in setup.py

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.

like image 546
Steve Sawyer Avatar asked Jun 17 '13 20:06

Steve Sawyer


People also ask

What is Package_dir in setup py?

package_dir = {'': 'lib'} in your setup script. The keys to this dictionary are package names, and an empty package name stands for the root package. The values are directory names relative to your distribution root.

Is setup py outdated?

py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).

What is install_requires in setup py?

install_requires is a section within the setup.py file in which you need to input a list of the minimum dependencies needed for a project to run correctly on the target operating system (such as ubuntu). When pip runs setup.py, it will install all of the dependencies listed in install_requires.


2 Answers

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'})
like image 176
merwok Avatar answered Oct 26 '22 15:10

merwok


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
like image 26
Alan CN Avatar answered Oct 26 '22 14:10

Alan CN