Ask Your Question
3

How can I use python's setuptools without the src directory?

asked 2022-08-04 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-04-08 22:00:00 +0000

woof gravatar image

You can use setuptools without the src directory by using the package_dir option in the setup() function. Here's an example:

from setuptools import setup, find_packages

setup(
    name='my_package',
    version='1.0.0',
    packages=find_packages(),
    package_dir={'': 'my_package'},  # specify the root package directory
    # other configuration options...
)

In this example, we assume that your package structure looks like this:

my_package/
├── __init__.py
├── module1.py
└── module2.py

With the packagedir option, we specify that the root package directory is 'mypackage'. This means that setuptools will look for Python modules in 'my_package' instead of the default 'src' directory.

You can then install and use your package like this:

pip install .

And import modules from your package like this:

from my_package.module1 import some_function

Note that you may also need to update your import statements to reflect the change in package directory.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-04 11:00:00 +0000

Seen: 7 times

Last updated: Apr 08 '22