【发布时间】:2016-08-11 19:47:59
【问题描述】:
我一直在尝试使用 setup.py 打包我的项目,但遇到了障碍。
我的文件结构如下:
root/
mypackage/
__init__.py
mysubmodule1/
__init__.py
mysubmodule2/
__init__.py
我在 setup.py 中使用以下配置,
from setuptools import setup, find_packages
# To use a consistent encoding
from os import path
import glob
here = path.abspath(path.dirname(__file__))
print(find_packages(exclude=['docs', 'tests*']))
setup(
name='mypackage',
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
install_requires=[...],
scripts=[...],
)
我在 virtualenv 中使用 python setup.py install 构建包,我打印的调试行显示 find_packages 位于我的所有包。
['mypackage', 'mypackage.submodule1', 'mypackage.submodule2']
当我导入我的包时,我尝试导入 mypackage.submodule1.class,但这引发了一个找不到模块的异常。 我检查了我所有的模块都在 virtualenv 站点包的输出蛋中,并且我可以导入我的根包。
dir(mypackage)的输出如下:
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypackage
>>> dir(mypackage)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__']
我错过了什么吗?我引用的所有开源项目都遵循这种模式。 谢谢
【问题讨论】:
标签: python