Cannot import local package installed with `pip install -e .`

Viewed 606

I have a package under development and also a few scripts that import this package. I am trying to install the package with developer mode using pip install -e . but then I cannot import it in my scripts. I have the following file structure where singlepixel is a package I am developing.

├── setup.py
├── singlepixel
│   ├── acquisition.py
│   ├── metadata.py
│   └── __init__.py
├── scripts
│   ├── script1.py
│   └── script2.py

My __init__.py has the following structure:

from .acquisition import init, setup, acquire, disconnect
from .metadata import MetaData, AcquisitionParameters

And my setup.py is:

from setuptools import setup, find_packages

setup(
    name='singlepixel',
    version='0.0.1',
    author='gbm',
    package_dir={"": "singlepixel"},
    packages=find_packages(where="singlepixel"))

From my understanding, I should be able to do a simple import statement in my script1.pysuch as from singlepixel import *, however it does not work and I get the following error instead:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'singlepixel'

Moreover it seems that I am not able to import the package anywhere even though I am using an anaconda environment. From my understanding, I should be able to import my package anywhere when using this environment just like any other package installed with pip install.

1 Answers

You don't have packages inside singlepixel/, that directory itself is a package. So remove

package_dir={"": "singlepixel"},

and change

packages=find_packages(where="singlepixel"))

to

packages=find_packages())
Related