I have created my first python package using setuptools. Running python -m build from the top level of my package directory seems to make the package just fine, and the package files are created in dist as expected. However when I install the package, the name of the installed package has the _ replaced by -, making it almost impossible to import into a python file.
Here is my directory layout:
(venv) cunninwe@MBLS015 dpu2 % tree /Users/cunninwe/Documents/dpu2
/Users/cunninwe/Documents/dpu2
├── Dockerfile
├── LICENSE
├── README.md
├── dist
│ ├── myorg_devops_utils-0.0.1-py3-none-any.whl
│ └── myorg_devops_utils-0.0.1.tar.gz
├── pyproject.toml
├── requirements.txt
├── src
│ ├── devops_python_utils_package
│ │ ├── __init__.py
│ │ ├── file0.py
│ │ ├── file1.py
│ │ ├── file2.py
│ │ ├── file3.py
│ │ ├── fileA.py
│ │ ├── file4.py
│ │ ├── file5.py
│ │ ├── file6.py
│ │ ├── file7.py
│ │ ├── fileB.py
│ │ ├── rcfile.rc
│ │ ├── file8.py
│ │ ├── file9.py
│ │ └── file10.py
│ └── myorg_devops_utils.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ └── top_level.txt
├── tests
│ ├── test_file1.py
│ ├── test_file2.py
│ ├── test_file3.py
│ ├── test_file4.py
│ ├── test_file5.py
│ ├── test_file6.py
│ ├── test_file7.py
│ └── test_file8.py
└── venv
My pyproject.toml file like this:
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "myorg_devops_utils"
version = "0.0.1"
authors = [
{ name="me", email="me@myorg.com" },
]
description = "Python utilities used by DevOps team"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
I am running python -m build from the root of this structure. I then change into the dist subdirectory and run the pip install of the whl file.
(venv) cunninwe@MBLS015 dist % python -m pip install myorg_devops_utils-0.0.1-py3-none-any.whl
Processing ./myorg_devops_utils-0.0.1-py3-none-any.whl
Installing collected packages: myorg-devops-utils
Successfully installed myorg-devops-utils-0.0.1
Environment: Mac
So:
- Why did this happen?
- How do I make it go away so I can actually use files from my package?
I have tried using importlib.import_module('myorg-devops-utils') but that doesn't work either.