3

I have a folder structure for my python package as follows

myproject
├── package
|    ├──api
|    |   ├── __init__.py
|    |   ├── main.py
|    |
|    ├──utils
|        ├── __init__.py
|        ├── helpers.py
|        ├── config.yml
├── MANIFEST.in
├── setup.py    

Content of setup.py

from setuptools import setup, find_packages

setup(name='package', 
version='1.0', 
packages=find_packages(),
include_package_data = True)

Content of MANIFEST.in

include package/utils/config.yml 

Content of helpers.py

import yaml
def add_():
    return 2+3

def config_data():
    with open('project/utils/config.yml') as f:
         yaml_data = yaml.safe_load(f)
    return yaml_data

Now I want to import helpers module in main.py

from package.utils import helpers
import yaml

print(helpers.add_())
print(helpers.config_data()) 

When I install this package in editable form as and ran main.py , everything is working fine

(base) C:\Users\qaise\myproject> pip install -e .

snapshot of output of main.py, i.e. output of add_ , and config_data {'qaiser':'alam'} is content of config.yml

enter image description here

Now when everything was working fine i tried to create wheel file for this package and install created wheel using pip

(base) C:\Users\qaise\myproject> python setup.py sdist bdist_wheel 
(base) C:\Users\qaise\myproject> pip install ./dist/package-1.0-py3-none-any.whl 

enter image description here

After this , I opened my jupyter notebook and tried to call the function from the helper module I am getting error no module named package, it seemed like it is a path problem but I am not able to resolve it.

enter image description here

qaiser
  • 2,770
  • 2
  • 17
  • 29

0 Answers0