Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaging Tutorial Hatchling Build resulted in ModuleNotFound after installing libary; Setuptools works correctly #662

Closed
crewz07 opened this issue Apr 16, 2023 · 2 comments

Comments

@crewz07
Copy link

crewz07 commented Apr 16, 2023

Using Ubuntu; python 3.10.6; working in the virtual environment.

(venv) andrew@andrew-Surface-Book-2:~/Code/sandbox/firstPythonPackage$ pip install ./packaging_tutorial
Processing ./packaging_tutorial
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: example_project_andrewk
  Building wheel for example_project_andrewk (pyproject.toml) ... done
  Created wheel for example_project_andrewk: filename=example_project_andrewk-0.1.1-py3-none-any.whl size=2604 sha256=70c66a949ba92af0a778f88be640f1722a48b639d6b0bf4844aee2ddf10a92e2
  Stored in directory: /tmp/pip-ephem-wheel-cache-a1fx_77o/wheels/7d/7a/b7/27a3ef84323c9fd354c900433fc50b3690755fa39e912ed852
Successfully built example_project_andrewk
Installing collected packages: example_project_andrewk
  Attempting uninstall: example_project_andrewk
    Found existing installation: example_project_andrewk 0.1.0
    Uninstalling example_project_andrewk-0.1.0:
      Successfully uninstalled example_project_andrewk-0.1.0
Successfully installed example_project_andrewk-0.1.1
(venv) andrew@andrew-Surface-Book-2:~/Code/sandbox/firstPythonPackage$ pip list
Package                 Version
----------------------- -------
build                   0.10.0
example_project_andrewk 0.1.1
packaging               23.1
pip                     22.0.2
pyproject_hooks         1.0.0
setuptools              59.6.0
tomli                   2.0.1

Running the following commands in the python3 virtual environment would show the example_project_andrewk library available.

import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
   for i in installed_packages])
print(installed_packages_list)

However the import statement from the python3 console from example_package_andrewk import example resulted in ModuleNotFound Issue.

Swapping to setuptools instead of hatchling seems to work correclty.

@crewz07 crewz07 changed the title Packaging Tutorial Hatchling Build resulted in ModuleNotFound after installing libary; Setup works correctly Packaging Tutorial Hatchling Build resulted in ModuleNotFound after installing libary; Setuptools works correctly Apr 16, 2023
@henryiii
Copy link
Contributor

The name of the project needs to match the module name for hatchling to automatically find it. If you want them different, you can tell hatchling where your package(s) are via an extra config setting.

@crewz07
Copy link
Author

crewz07 commented Apr 16, 2023

Ah, that makes sense Thank you for the reply.

@crewz07 crewz07 closed this as completed Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants