How do I import a Python package everywhere in my system?

Viewed 32

I am working on a Python package, which has the following structure

m2too
├── bin
├── m2too
│   ├── m2too.egg-info
│   │   ├── dependency_links.txt
│   │   ├── PKG-INFO
│   │   ├── requires.txt
│   │   ├── SOURCES.txt
│   │   └── top_level.txt
│   ├── __pycache__
│   │   ├── aero.cpython-39.pyc
│   │   ├── appo.cpython-39.pyc
│   │   ├── dataprep.cpython-39.pyc
│   │   ├── fitter.cpython-39.pyc
│   │   ├── __init__.cpython-39.pyc
│   │   └── stat.cpython-39.pyc
│   ├── aero.py
│   ├── appo.py
│   ├── dataprep.py
│   ├── fitter.py
│   ├── __init__.py
│   ├── run.py
│   └── stat.py
├── CHANGES.txt
├── LICENSE.txt
├── README.txt
├── setup.cfg
└── setup.py

The package name is m2too. From the project base folder, m2too, I can pip install -e ., which works fine, and from within that directory I can run all the scripts, import m2too from within any Python interpreter, etc.

However, whenever I cd to anywhere else in the system (including m2too/m2too), any import m2too statement results in the following:

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

I can not figure out why this is.

EDIT My setup.py looks like this:

from setuptools import setup

setup()

My setup.cfg looks like this:

[metadata]
name = m2too
version = 0.1.0
author = Some Name
author_email = somename@somewhe.re
description = A package to do stuff

[options]
package_dir =
    = m2too
packages = find:
python_requires = >=3.6
install_requires = 
    numpy
    matplotlib
    pandas
    scipy

[options.packages.find]
where = m2too
1 Answers

Please read Python packaging documentation.

Usually problems like these are solved by having a virtual environment (venv) that has a specific Python interpreter setup and which you can activate anywhere in your system.

Related