安装包后,Python wheel:“ ModuleNotFoundError”

时间:2018-07-03 10:54:27

标签: python module python-wheel egg

操作系统:Windows 7

Python:3.6

我正在尝试创建和安装python wheel软件包。建筑物运行良好,但是在安装后将模块导入项目时,出现“ ModuleNotFound”错误。我的项目具有以下结构:

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

我的setup.py用于创建滚轮包:

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",
    ),
)

在uart.py中,我这样做:

from utils import ctimer

安装后,我将软件包导入另一个项目:

#Test.py

from my_lib.phlayer.uart import Uart

def main(args=None):
    pass

if __name__ == "__main__":
    main()

我得到了错误:

  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'

因此,似乎python无法在其他软件包中找到正确的模块。我是否需要在setup.py中指定正确的路径 在创建轮包之前?

1 个答案:

答案 0 :(得分:0)

您必须指定完整的模块名称:

from my_lib.utils import ctimer
相关问题