我有一个包裹cclogger
。该目录有一个__init__.py
文件,其中包含一些用于加载配置的代码。当我尝试api_main.py
使用以下命令运行该目录中的文件时...
python -m cclogger.api_main
我收到以下错误:-
config loaded
Instantiating DB with: cclogger/test123@localhost:x
Instantiated ParseCentral
Register parser called by : CitiIndia
Registered parser for email: CitiAlert.India@citicorp.com
Instantiated SmsParseCentral
Register parser called by : Citi Bank
Registered sms parser for address: lm-citibk
Register parser called by : HDFC Bank
Registered sms parser for address: am-hdfcbk
Traceback (most recent call last):
File "/Users/applegrew/Dropbox/Credit Expense/cclogger/cclogger/api_main.py", line 4, in <module>
from .bottle import run, default_app, debug, get
ValueError: Attempted relative import in non-package
错误上方显示的消息来自同一包中的模块,这些模块由__init__.py
.
api_main.py 中的代码是:-
import re
import os
from .bottle import run, default_app, debug, get
from .common_util import date_str_to_datetime, UTCOffset, date_filter
#app = Bottle()
default_app().router.add_filter('date', date_filter)
from . import api, dev
@get('/index')
def index():
return "CCLogger API main live and kicking."
if dev:
debug(True)
run(reloader=True, port=9000)
else:
os.chdir(os.path.dirname(__file__))
application = default_app()
我有 python 2.7.1。
我究竟做错了什么?您可以在https://github.com/applegrew/cclogger/tree/master/cclogger查看完整代码