我是 Python 新手,正在寻求某种帮助。下面的 Python Lambda 函数引发了我预期的错误。
Unable to import module 'lambda_function': No module named 'stomp'
Python Lambda 脚本:-
import time
import boto3
import stomp
kinesis_client = boto3.client('kinesis')
class Listener(stomp.ConnectionListener):
def on_error(self, headers, message):
print('received an error "%s"' % message)
def on_message(self, headers, message):
print('received a message "%s"' % message)
kinesis_client.put_record(
StreamName='inter-lambda',
Data=u'{}\r\n'.format(message).encode('utf-8'),
PartitionKey='0'
)
我使用mac执行命令,错误如下:-
sudo pip install stompy -t /Users/kalyanbhave/Documents/stomp/
Password:
The directory '/Users/kalyanbhave/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/kalyanbhave/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting stompy
Downloading https://files.pythonhosted.org/packages/af/21/8f3bdf1f304ba65847706c29d1950525513ec11d941ed0630ee8af51b361/stompy-0.2.9.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/tmp/pip-install-rgmh5da6/stompy/setup.py", line 2, in <module>
from stompy import distmeta
File "/private/tmp/pip-install-rgmh5da6/stompy/stompy/__init__.py", line 1, in <module>
from stompy.stomp import Stomp, NotConnectedError
File "/private/tmp/pip-install-rgmh5da6/stompy/stompy/stomp.py", line 49
except socket.timeout, exc:
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-rgmh5da6/stompy/
最佳答案
您正在使用 AWS Lambda。默认情况下不包含模块 stomp
。
您需要创建自己的部署包,包括 stomp
,如所述 here .
关于python - 无法导入模块 'lambda_function' : No module named 'stomp' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53376117/