我在使用setuptools python setup.py install
后努力运行我的应用程序。尽管变量位于正确的模块中,但导致导入错误ImportError: cannot import name 'db'
失败。当我打印dir(package)
时,我得到输出:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
好像变量根本不在文件中。但是,当我运行python setup.py develop
时,应用程序正常工作,同样的打印返回:
['Account', 'Constants', 'SQLAlchemy', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'current_app', 'db', 'requests', 'take_snapshot']
显示缺失的变量。
我的完整setup.py文件如下所示:
from setuptools import setup, find_packages
setup(
name='accountService',
packages=find_packages(),
include_package_data=True,
install_requires=[
'certifi==2017.11.5',
'chardet==3.0.4',
'click==6.7',
'Flask==0.12.2',
'Flask-API==1.0',
'Flask-SQLAlchemy==2.3.2',
'Flask-Testing==0.7.1',
'idna==2.6',
'itsdangerous==0.24',
'Jinja2==2.10',
'MarkupSafe==1.0',
'requests==2.18.4',
'SQLAlchemy==1.1.15',
'urllib3==1.22',
'Werkzeug==0.13',
],
setup_requires=[
'pytest-runner'
],
tests_require=[
'pytest'
],
)
我的蛋SOURCES.txt是:
README.md
setup.cfg
setup.py
accountService/__init__.py
accountService/factory.py
accountService/run_app.py
accountService.egg-info/PKG-INFO
accountService.egg-info/SOURCES.txt
accountService.egg-info/dependency_links.txt
accountService.egg-info/requires.txt
accountService.egg-info/top_level.txt
accountService/blueprints/__init__.py
accountService/blueprints/accountService.py
accountService/eventSourcing/__init__.py
accountService/eventSourcing/aggregates.py
accountService/eventSourcing/commands.py
accountService/eventSourcing/events.py
accountService/eventSourcing/handlers.py
accountService/eventSourcing/util.py
tests/__init__.py
tests/test_account_service.py
tests/util.py