【问题标题】:Python eggs and module as pluginPython 鸡蛋和模块作为插件
【发布时间】:2011-12-15 22:23:02
【问题描述】:

我有这些鸡蛋:

~/test/lib/
├── a-1.0-py2.7.egg
│   ├── a
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   └── EGG-INFO
│       └── ...
├── a.b-1.0-py2.7.egg
│   ├── a
│   │   └── b
│   │       ├── __init__.py
│   │       └── __init__.pyc
│   └── EGG-INFO
│       └── ...
├── easy-install.pth
├── site.py
└── site.pyc

a/__init__.py 是:

print "a"

a/b/__init__.py 是:

print "a.b"

因此,“a.b”是“a”的“插件”。我会单独安装它(和大多数其他人一样)。 但在这种配置中,我的想法行不通:

>>> import a
a
>>> import a.b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named b
>>> 

应该是怎样的?

【问题讨论】:

    标签: python plugins egg


    【解决方案1】:

    检查你生成的 egg 文件,如果有一个模块 a.b.

    如果没有,请尝试使用 find_packages 注册您的模块。

    from setuptools import setup, find_packages setup( name='pypack', version='0.1', packages=find_packages(), ...
    ├── a.b-1.0-py2.7.egg
    │   ├── a
    │   ├── __init__.py
    │   └── __init__.pyc
    │   │   └── b
    │   │       ├── __init__.py
    │   │       └── __init__.pyc
    │   └── EGG-INFO
    │       └── ...
    

    每个文件夹都应该有一个

    __init__.py 
    

    【讨论】:

    • 没有。这不起作用,因为 python 在“a”中搜索“b”模块。它不会尝试导入“a.b”鸡蛋,只是“a”。是的,在“a.b”鸡蛋文件夹“a”中没有 __init__.py 文件。没关系。
    猜你喜欢
    • 1970-01-01
    • 2011-02-17
    • 2017-03-08
    • 2016-03-03
    • 2013-05-22
    • 2011-08-29
    • 2017-06-25
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多