-3

I’m trying to install locally a personal package that I called circuits.

I installed it with pip install -e ., it shows up in the pip list, but I have a ModuleNotFoundError when I try to import it.

(venv) pip install -e .
Obtaining file:///Users/me/my_project/circuits
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /Users/me/my_project/venv/lib/python3.9/site-packages (from circuits==0.1.0) (1.23.3)
Requirement already satisfied: tabulate in /Users/me/my_project/venv/lib/python3.9/site-packages (from circuits==0.1.0) (0.8.10)
Building wheels for collected packages: circuits
  Building editable for circuits (pyproject.toml) ... done
  Created wheel for circuits: filename=circuits-0.1.0-0.editable-py3-none-any.whl size=2277 sha256=a1ab6479e6d2761d7aae5cb156dd239001e54c397e712e279c6331b9ed217d0d
  Stored in directory: /private/var/folders/mw/k72xg0bx6yz48vzqq4fbgsk80000gn/T/pip-ephem-wheel-cache-d5600og9/wheels/6d/ed/4d/6b97818bf8ea2c80312b9134aa990bb61b776a1399143dec7d
Successfully built circuits
Installing collected packages: circuits
  Attempting uninstall: circuits
    Found existing installation: circuits 0.1.0
    Uninstalling circuits-0.1.0:
      Successfully uninstalled circuits-0.1.0
Successfully installed circuits-0.1.0

(venv) cd ../projects

(venv) python -c "import circuits"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'circuits'

It turns out that the package is not added to my sys.path, although other packages that also are on my laptop are when I install them the same way.

I suspect that there may be some link with the fact that there already exists a package with the same name on pypi (https://pypi.org/project/circuits/)

  • which python returns /Users/me/my_project/venv/bin/python
  • which pip returns /Users/me/my_project/venv/bin/pip

Project directory structure:

.
├── README.md
├── build
│   └── bdist.macosx-12-arm64
├── circuits
│   ├── file_a.py
│   ├── file_b.py
│   └── file_c.py
├── circuits.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   ├── requires.txt
│   └── top_level.txt
├── pyproject.toml
├── setup.cfg

pyproject.toml content:

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

setup.cfg content:

[metadata]
name = circuits
version = 0.1.0
authors = ["me"]

[options]
packages = find:
install_requires =
    numpy

I use MacOS 12.6

--

Edit 1: added precisions on the config and project tree, removed screenshot.

Billbucket
  • 165
  • 2
  • 9

3 Answers3

-1

Try this

python -m pip install -e .
-2

The outcome of pip install -e . is mostly based on project structure and on the content of package metadata files like setup.py, setup.cfg, pyproject.toml. These files are used to instruct pip how to install a Python package.

I suggest you to review how to build Python packages and how write the metadata files. Take a look here, it should give a basis: https://python-packaging-tutorial.readthedocs.io/en/latest/setup_py.html.

Another thing is that I see on the provided screenshot you install your package into its Virtual environment. I'm not sure if that's really what your need. In this case even if pip install -e . worked you'd only have access to your package from that venv, not from system Python installation.

If you just want to test your package interactively, just enter venv and run Python interpreter from the root project dir. Then you'll have access to own packages/modules and its dependencies installed to the venv.

Otherwise, if you need to install your package into system Python env, you need to pip install -e . outside of project's venv.

Antonio
  • 304
  • 2
  • 11
-2

As @sinoroc pointed out in the comments, it was missing a __init__.py file in circuits

Billbucket
  • 165
  • 2
  • 9