I have a rather small package, with only the single __init__.py at the top-level, which I attempt to install with pip-3.11 install --user ..
Pip duly processes my pyproject.toml, checking all of the dependencies, and ends with these reassuring messages:
Building wheels for collected packages: mypackage Building wheel for mypackage (pyproject.toml) ... done Created wheel for mypackage: filename=mypackage-0.1-py3-none-any.whl size=3251 sha256=4a4fbb798d9557c52b4751b545cebcca75501a238092d02d055aea4147680a2f Stored in directory: /tmp/pip-ephem-wheel-cache-nm8w_8n1/wheels/b7/e9/c7/84dde047e428daca2ad6421e22f0c84327b33be5ac57e2c8e2 Successfully built mypackage Installing collected packages: mypackage Successfully installed mypackage-0.1 After this, I see my __init__.py copied into the newly-created build/lib/ subdirectory. The ~/.local/lib/python3.11/site-packages/mypackage-0.1.dist-info bnysms.egg-info is also created, with various files describing the package in it.
But there is no ~/.local/lib/python3.11/site-packages/mypackage/ itself -- and my package is not, in fact, installed. Attempting to run python3.11 -m mypackage responds with No module named mypackage.
The pip-3.11 freeze | grep mypackage lists it without version: mypackage @ file:///home/me/mypackage.
Following @sinoroc's suggestion, I renamed the __init__.pyinto myproject.py and modified the pyproject.toml thus:
[project] authors = [ {name = "John Smith", email = "[email protected]"} ] name = "mypackage" description = "Do the thing" version = "0.1" requires-python = ">= 3.6" dependencies = [ "requests", "requests_kerberos", "pyspnego" ] readme = "README.md" keywords = ["SMS", "secrets"] classifiers = [ "Development Status :: 4 - Beta", "Topic :: Software Development :: Secrets" ] [project.optional-dependencies] decodejwt = ["pyjwt"] [tool.setuptools] py-modules = ["myproject"] With this I can create a "wheel" using python3.11 -m build --wheel --outdir /tmp .. The resulting /tmp/mypackage-0.1-py3-none-any.whl contains the following files:
mypackage.pymypackage-0.1.dist-info/METADATAmypackage-0.1.dist-info/WHEELmypackage-0.1.dist-info/top_level.txtmypackage-0.1.dist-info/RECORD
This .whl file can then be used to install the package: pip-3.11 install --user --find-links=/tmp/ mypackage. The package then works -- it can be both imported and/or used from command-line python3.11 -m mypackage. (The README.md is not included for some reason, but I don't really care.)
Life is good, although I don't understand, why this renaming was necessary :(
pip-3.11 install --user mypackagewheremypackageis the directory containing__init__.py?__init__.pymeans that you intend to have an import package, in other words a directory. Butpy-modulesis for single file import modules. -- I recommend you follow this tutorial: <packaging.python.org/en/latest/tutorials/packaging-projects>, and pay particular attention to the project directory structure.version="0.1"in the TOML file -- and this version is cited in the installation-log I quoted...