I have a project with this setup.py
file:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="",
version="0.0.1",
author="",
author_email="",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(where="./src", exclude=("./tests",)),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.8',
)
This is my project directory structure (first two levels):
$ tree -L 2
.
├── README.md
├── setup.py
├── src
│ └── my_pkg
└── tests
├── conftest.py
├── data
├── __init__.py
├── integration
├── __pycache__
└── unit
When I run any setuptools command, I get the following error:
$ python setup.py build
running build
running build_py
error: package directory 'my_pkg' does not exist
The same happens for other commands like python setup.py develop
and python setup.py bdist-wheel
.
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 been following the documentation, and it does look the the my_pkg
module is discovered at some point.
Why does build_py
fail to find it?
Type “ pip install setuptools ” (without quotes) in the command line and hit Enter again. This installs setuptools for your default Python installation. The previous command may not work if you have both Python versions 2 and 3 on your computer.
Follow the below steps to install the Setuptools on Windows using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from here. Step 2: Extract the downloaded package using the given command. Step 3: Go to the setuptools-60.2.
the setuptools is not part of the python vanilla codebase, hence not a vanilla modules. python.org installers or mac homebrew will install it for you, but if someone compile the python by himself or install it on some linux distribution he may not get it and will need to install it by himself.
package_dir has to be a relative path, not an absolute path. The distutils layer under setuptools tries to reject absolute paths, but the C: confuses it. It ends up converting your path to Note the missing backslash between C: and Users.
Python setuptools is a module that deals with the Python package development process. It is a library that is designed to allow packing Python projects in a simplified manner. What’s the difference between Python setuptools Vs. distutils? What is the difference between easy_install and setup.py (pip package creation) ? This module is external.
Although setuptools allows developers to create a very complex mapping between directory names and package names, it is better to keep it simple and reflect the desired package hierarchy in the directory structure, preserving the same names. Automatic discovery is a beta feature and might change in the future.
Historically, there were two methods to create namespace packages. One is the pkg_resources style supported by setuptools and the other one being pkgutils style offered by pkgutils module in Python. Both are now considered deprecated despite the fact they still linger in many existing packages.
find_packages()
automatically generates package names. That is, in your case all it does is generate ['my_pkg']
. It doesn't actually tell setup()
where to find my_pkg
, just that it should expect to find a package called my_pkg
somewhere. You have to separately tell setup()
where it should look for packages. Is this confusing and counter intuitive? Yes. Anyway, you can tell setup()
where to find my_pkg
by using the package_dir
argument. eg.
package_dir={"":"src"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With