gpt4 book ai didi

python - 如何 cx 卡住 Boto3

转载 作者:太空宇宙 更新时间:2023-11-04 03:03:05 27 4
gpt4 key购买 nike

我创建了这个简单的 python 程序,它向 SQS 发送消息然后检索它。它使用 python 2.7.11 工作。

import boto3 
sqs = boto3.client('sqs')
queue = sqs.get_queue_by_name(QueueName='some-que-name')
queue.send_message(MessageBody='{"phrase": "It\'s the end of the world as we know it" }' )
for message in queue.receive_messages():
print message.body

然后我用这个脚本 cxFreeze 它:

from cx_Freeze import setup, Executable

include_mods = []

excludes = ['tkinter', 'cltk']

buildOptions = dict(packages=[], excludes=excludes, includes=include_mods)


executables = [
Executable('./frozen_boto_3_test.py', 'Console')
]

setup(name='Boto3FrozenTest',
version='1',
description='A test to make sure boto3 is working well when frozen',
options=dict(build_exe=buildOptions),
executables=executables)

然后当我尝试运行卡住的代码时出现此错误

Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec(code, m.__dict__)
File "./frozen_boto_3_test.py", line 1, in <module>
import boto3
File "/usr/local/lib/python2.7/site-packages/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/usr/local/lib/python2.7/site-packages/boto3/session.py", line 17, in <module>
import botocore.session
File "/usr/local/lib/python2.7/site-packages/botocore/session.py", line 25, in <module>
import botocore.configloader
File "/usr/local/lib/python2.7/site-packages/botocore/configloader.py", line 18, in <module>
from six.moves import configparser
File "/usr/local/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named ConfigParser

除了这个问题,库似乎动态加载不是 s3、dynamo 或其他服务的服务。

是否有卡住 boto3 的方法?

最佳答案

错误表明正在进行隐藏(动态)导入。如果您在告诉 cx_Freeze 要包含的模块列表中包含它正在寻找的模块 (ConfigParser),它应该可以工作。您可能需要多次执行此操作。

executables = [cx_Freeze.Executable("MyScript.py")]
includes = ["ConfigParser"]
buildOptions = dict(includes = includes)
cx_Freeze.setup(name, description, options = dict(build_exe = buildOptions),
executables = executables)

一旦你有了一个工作程序,你也可以这样做而不是操纵你的特定 setup.py。您可以在 cx_Freeze.hooks 模块中添加一个条目,看起来像这样:

def load_boto3(finder, module):
finder.IncludeModule("ConfigParser")

包括您在此过程中发现的任何其他内容。然后在此处创建拉取请求或问题:

https://bitbucket.org/anthony_tuininga/cx_freeze

关于python - 如何 cx 卡住 Boto3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40362094/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com