【问题标题】:Dependency not found in Python Wheel package in databricks在 databricks 的 Python Wheel 包中找不到依赖项
【发布时间】:2021-07-02 04:51:45
【问题描述】:

我创建了一个 python 轮文件,其中包含两个具有一些自定义模块的 python 文件(file1.py 和 file2.py)。 file2.py 依赖于 file1.py。

创建wheel文件后我的本地目录是这样的:

myfunc_wheel
├── build
|--myfunc.eg-info
└── myfuncpkg
     |_ __init__.py
     └── file1.py
     |__ file2.py
|__ dist
    |__myfunc-0.01-pu3-none-any.whl
|__ setup.py

file1.py:

def hello_world():
   print("hello world")

file2.py

import file1
#some functions

setup.py:

import setuptools

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

setuptools.setup(
    name="myfunc",
    version="0.0.1",
    author="xxx",
    author_email="x",
    description="xxxx",
    long_description=long_description,
    long_description_content_type="text/markdown",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.7',
)

当我在本地同时运行 file1 和 file2 时,它没有抛出错误。

但是当我在 Databricks 集群上安装了 wheel 文件并尝试在 Databricks 笔记本中导入模块后,它抛出了 file2 找不到 file1 的错误。

from myfuncpkf import file1
from myfuncpkg import file2


ModuleNotFoundError: No module named 'file1'

我也尝试过将整个路径放到 file1 中,但也没有用。

我应该如何调整我的文件以使依赖项在 Databricks 上工作?

【问题讨论】:

    标签: python jupyter-notebook databricks python-wheel


    【解决方案1】:

    要使目录成为包,您需要在每个文件夹中都有__init__.py。尝试在您的myfuncpkg 目录中放置一个空的__init__.py 文件。那应该可以解决问题。参考:https://realpython.com/lessons/package-initialization/

    【讨论】:

    • 感谢您的回复。我检查了我实际上在 myfuncpkg 中有一个 init.py。并且依赖项也适用于我的本地。但不知道为什么当我在数据块上使用它时它不起作用。
    猜你喜欢
    • 2018-10-14
    • 2014-11-03
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2020-08-01
    • 1970-01-01
    • 2020-04-12
    • 2015-06-27
    相关资源
    最近更新 更多