对于许多聪明人来说,这可能是一个蹩脚的问题,但我正在努力创建一个简单的python包。 我的dir结构包是:
address-book/
├── __init__.py
├── dist
│ └── book-0.1.tar.gz
├── address-book
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── person.py
│ └── person.pyc
├── address_book.egg-info
│ ├── PKG-INFO
│ ├── SOURCES.txt
│ ├── dependency_links.txt
│ ├── not-zip-safe
│ └── top_level.txt
├── setup.py
└── tests
├── __init__.py
├── __init__.pyc
├── person_test.py
└── person_test.pyc
setup.py如下:
from setuptools import setup, find_packages
setup(name='address-book',
version='0.1',
description='The funniest joke in the world',
url='http://github.com/storborg/funniest',
author='Address Book',
author_email='flyingcircus@example.com',
license='MIT',
packages=find_packages('.'),
test_suite="tests",
zip_safe=False)
SOURCES.txt:
setup.py
address-book/__init__.py
address-book/person.py
address_book.egg-info/PKG-INFO
address_book.egg-info/SOURCES.txt
address_book.egg-info/dependency_links.txt
address_book.egg-info/not-zip-safe
address_book.egg-info/top_level.txt
tests/__init__.py
tests/person_test.py
在person_test.py我无法导入person.py,可能是什么原因?
如果有人遇到同样的问题,我可以通过不使用连字符作为包名来解决问题。简单而有效!
答案 0 :(得分:2)
It looks like you have address-book
and address_book.egg-info
. I think it should be address-book.egg-info
.