python包eve的异常行为
Posted
技术标签:
【中文标题】python包eve的异常行为【英文标题】:Abnormal behavior of python package eve 【发布时间】:2019-05-29 01:38:36 【问题描述】:我已经在我的 windows 机器上安装了 eve 包,但是每次我关闭机器并尝试加载 eve 包时,我都会收到模块未找到错误。
尝试重新安装(顺便说一句,我使用最新的 pip 版本安装),我得到了
from eve import Eve
app=Eve()
app.run()
错误指向第二行。
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-79-46d1b24866c8> in <module>()
30 # host = '127.0.0.1'
31
---> 32 app = Eve()
33 # app.run()
34
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eve\flaskapp.py in __init__(self, import_name, settings, validator, data, auth, redis, url_converters, json_encoder, media, **kwargs)
158 self.settings = settings
159
--> 160 self.load_config()
161 self.validate_domain_struct()
162
~\AppData\Local\Continuum\anaconda3\lib\site-packages\eve\flaskapp.py in load_config(self)
275
276 try:
--> 277 self.config.from_pyfile(pyfile)
278 except:
279 raise
~\AppData\Local\Continuum\anaconda3\lib\site-packages\flask\config.py in from_pyfile(self, filename, silent)
128 try:
129 with open(filename, mode='rb') as config_file:
--> 130 exec(compile(config_file.read(), filename, 'exec'), d.__dict__)
131 except IOError as e:
132 if silent and e.errno in (
~\AppData\Local\Continuum\anaconda3\lib\site-packages\bokeh\settings.py in <module>()
9 from os.path import join, abspath, isdir
10
---> 11 from .util.paths import ROOT_DIR, bokehjsdir
12
13
ModuleNotFoundError: No module named 'config'
此外,我发现没有文件夹“lib”而是“Lib”。如果这是问题,我该如何解决?
但是,下面的代码可以运行,但运行时间为微秒,不像使用 api 运行后端服务器:
from eve import Eve
app=Eve
app.run
settings.py 文件:
# Let's just use the local mongod instance. Edit as needed.
# Please note that MONGO_HOST and MONGO_PORT could very well be left
# out as they already default to a bare bones local 'mongod' instance.
MONGO_HOST = 'localhost'
MONGO_PORT = 27017
MONGO_DBNAME = 'apitest'
# Enable reads (GET), inserts (POST) and DELETE for resources/collections
# (if you omit this line, the API will default to ['GET'] and provide
# read-only access to the endpoint).
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
# individual items (defaults to read-only item access).
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']
people =
# 'title' tag used in item links.
'item_title': 'person',
# by default the standard item entry point is defined as
# '/people/<ObjectId>/'. We leave it untouched, and we also enable an
# additional read-only entry point. This way consumers can also perform GET
# requests at '/people/<lastname>/'.
'additional_lookup':
'url': 'regex("[\w]+")',
'field': 'lastname'
,
'cache_control': 'max-age=10,must-revalidate',
'cache_expires': 10,
'resource_methods': ['GET', 'POST'],
# Schema definition, based on Cerberus grammar. Check the Cerberus project
# (https://github.com/pyeve/cerberus) for details.
'schema':
'firstname':
'type': 'string',
'minlength': 1,
'maxlength': 10,
,
'lastname':
'type': 'string',
'minlength': 1,
'maxlength': 15,
'required': True,
# talk about hard constraints! For the purpose of the demo
# 'lastname' is an API entry-point, so we need it to be unique.
'unique': True,
,
# 'role' is a list, and can only contain values from 'allowed'.
'role':
'type': 'list',
'allowed': ["author", "contributor", "copy"],
,
# An embedded 'strongly-typed' dictionary.
'location':
'type': 'dict',
'schema':
'address': 'type': 'string',
'city': 'type': 'string'
,
,
'born':
'type': 'datetime',
,
DOMAIN =
'people': people,
那么,有什么办法可以解决这个问题呢?
感谢任何帮助。
【问题讨论】:
【参考方案1】:快速测试后我没有这个问题。让我与你分享所有步骤,让我知道有什么不同。
1) 输入 Anaconda 提示符
2) conda create -n eswar python=3.6
3) conda 激活 eswar
4) 点安装前夕
5) 蟒蛇
5.1) 导入前夕
5.2) 退出()
6) 关闭windows机器
7) 重启windows机器
8) 进入 anaconda 提示符
9) conda 激活 eswar
10) 蟒蛇
11) 从前夕导入前夕
12) 一切看起来都很好。
您是否忘记在重启后激活您的环境?
【讨论】:
在导入之前我也没有问题,但是当我执行“app=Eve()”时,出现上述错误。 我已编辑问题以显示显示为造成问题的行。 @Eswar 抱歉,无法重现您的问题。 如果我使用“app=Eve”,没有大括号,它可以工作。同样,“app.run”可以工作,但不是应该的。 “app.run()”应该像后端服务器一样运行,打开直到你关闭它。但是,如果没有大括号,它会运行微秒。如果这样的问题敲响了警钟。请调查一下。 @Eswar 您能否也发布您的 settings.py?以上是关于python包eve的异常行为的主要内容,如果未能解决你的问题,请参考以下文章
python 包(多文件模块)的行为与一个大模块完全一样吗?