Documentation for using find_packages() and package_dir() might be wrong.
See original GitHub issueIn the docs it says under namespace packages it says:
setup(
name="namespace.mypackage",
version="0.1",
package_dir={'': 'src'},
packages=find_namespace_packages(where='src')
)
When I adapted this for my project I found that I had to change it slightly pointing explicitly to the __int__.py
making name the name of package_dir
explicit. Failure to do this led to Python files in the package’s top directory being excluded.
This is what I ended up with:
setup(
name='mypackage',
packages=find_packages('mypackage/__init__.py'),
package_dir={'mypackage':'mypackage'},
)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Knowledge Bits — Common Python Packaging Mistakes
An overview of common mistakes made in creating & building a Python package and how to avoid them.
Read more >Python setuptools: package directory does not exist
I suspect that it has to do with the src directory, as specified in the find_packages(where="./src") call in the setup.py . However, I've...
Read more >Package Discovery and Namespace Packages - Setuptools
Finding simple packages#. Let's start with the first tool. find: ( find_packages() ) takes a source directory and two lists ...
Read more >2. Writing the Setup Script — Python 3.11.1 documentation
Package data can be added to packages using the package_data keyword argument to the setup() function. The value must be a mapping from...
Read more >Build systems - pybind11 documentation
A helper file is provided with pybind11 that can simplify usage with setuptools. ... build ParallelCompile("NPY_NUM_BUILD_JOBS").install() setup(...).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Themanwithoutaplan I think you possibly misunderstand what
find_namespace_packages
are for. It is for adding packages in a Python 3 implicit namespace, sonamespace.mypackage
. There should be no files innamespace
, just packages. e.g.:Using that configuration, I am able to install
namespace.mypkg
using thissetup.py
:Which is exactly what we’re expecting. I think your second example is not correct either. If you do not have a namespace package and want to use the
src/
layout, lay out your code like this:And then your
setup.py
looks like this:I personally recommend the
src
layout using asetup.cfg
instead ofsetup.py
, like so:Then your
setup.py
looks like this:Good luck!
@pganssle Perhaps I’m misunderstanding something, but I’m trying to do something similar to what you’re describing (create a setuptools package with a namespace package in a directory somewhere below the root of the project), and as a sanity check I’m trying to run your example. It’s not installing as expected (this is on Python 3.5.6):