1

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.py
  • mypackage-0.1.dist-info/METADATA
  • mypackage-0.1.dist-info/WHEEL
  • mypackage-0.1.dist-info/top_level.txt
  • mypackage-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 :(

13
  • 2
    Is there a version attribute in the toml file? Commented Jun 3 at 21:52
  • Have you tried installing it from the parent directory, pip-3.11 install --user mypackage where mypackage is the directory containing __init__.py ? Commented Jun 4 at 8:08
  • 2
    __init__.py means that you intend to have an import package, in other words a directory. But py-modules is 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. Commented Jun 5 at 20:27
  • @LMC, of course, it has version="0.1" in the TOML file -- and this version is cited in the installation-log I quoted... Commented Jun 9 at 16:38
  • @vaizki, the method you suggested made no difference -- the same seemingly successful installation, which does not, in fact, install any code :-/ Commented Jun 9 at 16:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.