46

I am trying to install a library from the source that makes use of Poetry, but I get this error

error: Multiple top-level packages discovered in a flat-layout: ['tulips', 'fixtures'].
        
To avoid accidental inclusion of unwanted files or directories,
setuptools will not proceed with this build.
        
If you are trying to create a single distribution with multiple packages
on purpose, you should not rely on automatic discovery.
Instead, consider the following options:
        
1. set up custom discovery (`find` directive with `include` or `exclude`)
2. use a `src-layout`
3. explicitly set `py_modules` or `packages` with a list of names
        
To find more information, look for "package discovery" on setuptools docs

What do I need to do to fix it?

Rodrigo
  • 135
  • 4
  • 45
  • 107
  • What does you directory structure look like? – Alexander May 18 '22 at 18:38
  • @alexpdev I am trying to use this library directly, from the GitHub tar.gz https://github.com/woocart/tulips – Rodrigo May 18 '22 at 18:43
  • Then you should put the library in your `site-packages` directory or wherever you store your other packages – Alexander May 18 '22 at 18:47
  • `tulip` seems to be c++ library with python bindings, but it's not configured in a right way, as it seems, look [here](https://github.com/pypa/setuptools/issues/3197) – 0dminnimda May 18 '22 at 19:58

2 Answers2

43

Based on this comment on a GitHub issue, adding the following lines to your pyproject.toml might solve your problem:

[tool.setuptools]
py-modules = []

(For my case, the other workaround provided in that comment, i.e. adding py_modules=[] as a keyword argument to the setup() function in setup.py worked)

Warm_Duscher
  • 686
  • 7
  • 14
  • 8
    The error message even says "3. explicitly set `py_modules` or `packages` with a list of names". In my case specifying `packages = ["my_pkg_name"]` under `[tool.setuptools]` in `pyproject.toml` was the solution (I had another directory at the same level that confused `setuptools`). – András Aszódi Aug 22 '22 at 10:48
  • 4
    Note that this is an error message that presumably started appearing in setuptools version 61.0.0 (https://setuptools.pypa.io/en/latest/history.html#v61-0-0) in March 2022. Ubuntu 20.04 comes with version 45.2.0 installed, and it seems 22.04 comes with 59.6.0, so this is error will start showing up more often in the future. Also, just to clarify, the workaround requires that `py_modules=[]` be added as a *keyword argument* to the `setup()` function. – Martin Spacek Nov 15 '22 at 13:24
3

Adding the following in pyproject.toml worked for me. It was a repo with many folders but just one folder had the package code:

[tool.setuptools.packages.find]
where = ["."]  # list of folders that contain the packages (["."] by default)
include = ["<package name>"]  # package names should match these glob patterns (["*"] by default)
exclude = []  # exclude packages matching these glob patterns (empty by default)
namespaces = false  # to disable scanning PEP 420 namespaces (true by default)
Charalamm
  • 1,547
  • 1
  • 11
  • 27