python - 无法导入模块 'lambda_function' : No module named 'stomp'

标签 python python-3.x

我是 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/

相关文章:

python - 如何将对象转换为 three.js 模型加载器的 json 文件

python - 每行共享 y 轴

python-3.x - 将以毫秒为单位的13位unix时间转换为python中的时间戳

python - 有没有什么方法可以将一列 pandas 与其他每一列相乘并获得产品列表?

python - Python 类构造函数中是否有 `self.somevariable = somevariable` 的快捷方式?

Python 请求、CSV、Sha256 和 BOM

python - 如何在表驱动测试中使用assertRaises,其中一些测试会引发而其他测试则不会

python - Python 中是否有用于大精度复数的库?

python - 具有模拟和多个功能的单元测试

python - 停止 shutil.make_archive 向自身添加存档