Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python wheel: "ModuleNotFoundError" after installing package

OS: Windows 7

Python: 3.6

I'm trying to create and installing a python wheel package. The building works fine but when i import the module into project after installing it, i get a "ModuleNotFound" error. My project has the following structure:

my_lib/
    __init__.py
    phlayer/
        __init___.py
        uart.py
    utils/
        __init___.py
        ctimer.py 

My setup.py for creating the wheel package:

import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
    name="my_lib",
    version="0.0.1",
    author="",
    author_email="",
    description="",
    packages=setuptools.find_packages(),
    classifiers=(
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ),
)

In uart.py i do:

from utils import ctimer

After installing i import the package into another project:

#Test.py

from my_lib.phlayer.uart import Uart

def main(args=None):
    pass

if __name__ == "__main__":
    main()

And i get the error:

  File "C:/.../.../.../Test.py", line 9, in <module>
from my_lib.phlayer.uart import Uart
File "C:\...\...\...\...\...\...\test\env\lib\site-packages\my_lib\phlayer\uart.py", line 3, in <module>
from utils import ctimer
ModuleNotFoundError: No module named 'utils'

So it seems that python cannot find the correct module in the other package. Do i need to specify the correct paths in the setup.py before creating the wheel package?

like image 619
NoNAmE Avatar asked Nov 07 '22 05:11

NoNAmE


1 Answers

You have to specify full module names:

from my_lib.utils import ctimer
like image 87
phd Avatar answered Nov 14 '22 21:11

phd