【问题标题】:python module import fails when using pm2使用pm2时python模块导入失败
【发布时间】:2017-12-26 15:21:27
【问题描述】:

我尝试在我的 Ubuntu 服务器上运行一个 python3 脚本来通知关于 Twitter 帖子的信息。在命令行中执行此操作很好,但是当我在关闭控制台后使用 pm2 使脚本保持在线时,我收到此错误:

Traceback (most recent call last):
File "/root/projects/Twitterbot/main.py", line 1, in <module>
from tweepy.streaming import StreamListener
ImportError: No module named tweepy.streaming

当我将解释器从 python 切换到 python3 时,什么都没有发生,它不会崩溃。它需要一些 RAM,但它似乎没有做任何事情。

有人知道可能是什么问题吗?另一个 Python 脚本(导入了很多东西)运行良好,没有任何问题。

我已经使用 pip 重新安装了 tweepy 但没有任何变化

【问题讨论】:

  • 你为 python 2 安装了 tweepy 吗?
  • 可能与你的 python 路径有关
  • 您是否导入了 tweepy 和/或 tweepy.Stream?
  • @CaryShindell 我只是跑了pip install tweepy @arodjabel 我怎样才能知道这是否是问题
  • 等一下,你说你的脚本在 python3 中??

标签: python python-module pm2


【解决方案1】:

but it doesn't seem to do anything

我遇到了类似的问题,原来python3 默认使用pm2nohup 缓冲所有输出。所以日志不会显示任何内容,pm2 monit 不会显示任何内容。

使用-u 标志运行python3 以尽快刷新所有内容。

pm2 start myscript.py --interpreter python3 --interpreter-args -u

【讨论】:

  • 我不确定机器人是否启动了。我现在正在用 nodejs 构建自己的,在 python 中太糟糕了;)
猜你喜欢
  • 1970-01-01
  • 2013-12-03
  • 2020-05-21
  • 2011-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
  • 2019-04-28
相关资源
最近更新 更多