Search code examples
pythonpippython-importimporterror

How to correctly import function from src module


I have a project folder:

project
├── notebooks
│   └── EDA.ipynb
├── setup.py
└── src
    ├── data
    │   ├── make_data.py
    │   └── __init__.py
    └── __init__.py

The content in setup.py is:

from setuptools import find_packages, setup

setup(
    name='src',
    packages=find_packages(),
    version='0.1.0',
    description='',
    author='AG',
    license='MIT')

After using pip install . from project\ to make my src a python module I can see the module src when I make conda list... But when I try to import some function from make_data.py when I am working in EDA.ipynb:

from src.data.make_data import some_func

I get:

ModuleNotFoundError: No module named 'src'

What am I doing wrong?


Solution

  • Is the virtual environment where you installed 'src' same, where you are trying this.

    Pls. run the

    pip list
    

    in that virtual environment to check if 'src' is installed.

    Also, pls. check the import statement in the python interpreter of your virtual env.