'ImportError after successful installation with pip
I have created a skeleton package here, and I cannot seem to build and then test my own project.
src/main.py contains a single function and tests/unit.py tries to import and test that one function with from mofdb.main import add_one
├── LICENSE
├── dist
│ ├── mofdb-0.0.3-py3-none-any.whl
│ └── mofdb-0.0.3.tar.gz
├── pyproject.toml
├── setup.cfg
├── src
│ ├── __init__.py
│ ├── __pycache__
│ │ └── __init__.cpython-39.pyc
│ ├── main.py
│ └── mofdb.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ └── top_level.txt
└── tests
└── unit.py
Here's my attempt to run the tests:
python3 -m build
python3 -m pip install dist/mofdb-0.0.3.tar.gz
> Successfully installed mofdb-0.0.3
python3 tests.unit.py
> Traceback (most recent call last):
> File "/Users/n8ta/Desktop/mofdb-client/tests/unit.py", line 2, in <module>
> from mofdb.main import add_one
> ModuleNotFoundError: No module named 'mofdb'
python3 -m pip freeze
> matplotlib==3.3.3
> mofdb @ file:///Users/n8ta/Desktop/mofdb-client/dist/mofdb-0.0.3-py3-none-any.whl
> monty==2021.12.1
> ...
You can see from pip freeze that my module exists. But cannot be found for some reason.
And here's my setup.cfg
[metadata]
name = mofdb
version = 0.0.3
author = Nathaniel Tracy-Amoroso
author_email = omitted
description = Simple client for fetching data from mofdb
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/n8ta/mofdb-client
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent
[options]
package_dir =
= src
packages = find:
python_requires = >=3.6
[options.packages.find]
where = src
What am I missing?
Solution 1:[1]
Since I specified the package_dir as src that becomes the root and any folders under that are modules. I mistakenly assumed that module name was the package name and that files under src would be modules.
.
??? LICENSE
??? __init__.py
??? pyproject.toml
??? setup.cfg
??? src
? ??? mofdb <--- THIS DIR IS THE MODULE NAME
? ? ??? __init__.py
? ? ??? main.py
? ??? mofdb.egg-info
? ? ??? PKG-INFO
? ? ??? SOURCES.txt
? ? ??? dependency_links.txt
? ? ??? top_level.txt
? ??? test <-- This would also be an available module
? ??? run.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | nlta |
