【问题标题】:Python module not installing completelyPython模块未完全安装
【发布时间】:2019-01-01 18:49:09
【问题描述】:

我创建了一个具有以下层次结构的 python 模块

Git 存储库:Zeus | Machine Learning Library

但是每当我运行命令时

python setup.py install

它成功安装了模块,但是当我尝试从子模块中导入任何东西时,它给出了一个错误,例如。

当我在我的 python 终端中运行它时

import zeus

它工作得很好,但是当我运行它时

from zeus.tree import classifiers

它给了我以下错误

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    from zeus.tree import classifiers
ModuleNotFoundError: No module named 'zeus.tree'

我猜是我的 init.py 的问题,但不知道到底是什么。

【问题讨论】:

  • 您没有将子模块添加到setup.py
  • 你能告诉我如何添加它们吗?
  • 你也可以分享你的setup.py文件吗?
  • 你可以在 GitHub 存储库中找到 setup.py 文件,我在上面分享了我的 repo 的链接。

标签: python python-3.x python-packaging


【解决方案1】:
    # -*- coding: utf-8 -*-

    from distutils.core import setup

    setup(
        name = "zeus",
        version = "0.1",
        author = "yourname",
        author_email = "youraddress@xyz.com",
        description = ("A simple and easy to use Machine Learning Library."),
        license = "GPL-2,0",
        packages=['zeus', 'zeus.tree', 'zeus.linear_regressors'],
        install_requires=['numpy'],
        zip_safe=False
    )

您的包装不包含导致导入错误的子模块。更改后的行是:

    packages=['zeus', 'zeus.tree', 'zeus.linear_regressors'] 

相反,您只有:

    packages=['zeus']

【讨论】:

    猜你喜欢
    • 2016-09-08
    • 2011-04-30
    • 2021-12-28
    • 2013-08-26
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 2017-07-24
    • 2016-04-08
    相关资源
    最近更新 更多