ModuleNotFoundError: No module named 'telebot' on heroku

ModuleNotFoundError: No module named 'telebot' on heroku

这是官方文档https://github.com/python-telegram-bot/python-telegram-bot。如何在 heroku 上使用 pip install python-telegram-bot --upgrade。 这些是崩溃的消息。

2022-05-14T19:57:10.129393+00:00 heroku[web.1]: State changed from starting to crashed
2022-05-14T19:57:10.133517+00:00 heroku[web.1]: State changed from crashed to starting
2022-05-14T19:57:13.000000+00:00 app[api]: Build succeeded
2022-05-14T19:57:13.393948+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2022-05-14T19:57:14.270178+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-05-14T19:57:14.270671+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [4] [INFO] Listening at: http://0.0.0.0:20713 (4)
2022-05-14T19:57:14.270711+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [4] [INFO] Using worker: sync
2022-05-14T19:57:14.274010+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [9] [INFO] Booting worker with pid: 9
2022-05-14T19:57:14.327970+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [10] [INFO] Booting worker with pid: 10
2022-05-14T19:57:14.372053+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [9] [ERROR] Exception in worker process
2022-05-14T19:57:14.372057+00:00 app[web.1]: Traceback (most recent call last):
2022-05-14T19:57:14.372065+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-05-14T19:57:14.372066+00:00 app[web.1]: worker.init_process()
2022-05-14T19:57:14.372066+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process       
2022-05-14T19:57:14.372066+00:00 app[web.1]: self.load_wsgi()
2022-05-14T19:57:14.372067+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-05-14T19:57:14.372067+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-05-14T19:57:14.372067+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-05-14T19:57:14.372067+00:00 app[web.1]: self.callable = self.load()
2022-05-14T19:57:14.372068+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-05-14T19:57:14.372068+00:00 app[web.1]: return self.load_wsgiapp()
2022-05-14T19:57:14.372068+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-05-14T19:57:14.372068+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-05-14T19:57:14.372069+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
2022-05-14T19:57:14.372069+00:00 app[web.1]: mod = importlib.import_module(module)
2022-05-14T19:57:14.372069+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-05-14T19:57:14.372070+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-05-14T19:57:14.372070+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-05-14T19:57:14.372070+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-05-14T19:57:14.372070+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-05-14T19:57:14.372070+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-05-14T19:57:14.372071+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-05-14T19:57:14.372071+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-05-14T19:57:14.372071+00:00 app[web.1]: File "/app/app.py", line 3, in <module>
2022-05-14T19:57:14.372071+00:00 app[web.1]: import telebot
2022-05-14T19:57:14.372071+00:00 app[web.1]: ModuleNotFoundError: No module named 'telebot'
2022-05-14T19:57:14.372143+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-05-14T19:57:14.433579+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [10] [ERROR] Exception in worker process
2022-05-14T19:57:14.433580+00:00 app[web.1]: Traceback (most recent call last):
2022-05-14T19:57:14.433580+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
2022-05-14T19:57:14.433581+00:00 app[web.1]: worker.init_process()
2022-05-14T19:57:14.433581+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 134, in init_process       
2022-05-14T19:57:14.433581+00:00 app[web.1]: self.load_wsgi()
2022-05-14T19:57:14.433582+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
2022-05-14T19:57:14.433582+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2022-05-14T19:57:14.433582+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi
2022-05-14T19:57:14.433582+00:00 app[web.1]: self.callable = self.load()
2022-05-14T19:57:14.433583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
2022-05-14T19:57:14.433583+00:00 app[web.1]: return self.load_wsgiapp()
2022-05-14T19:57:14.433583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
2022-05-14T19:57:14.433583+00:00 app[web.1]: return util.import_app(self.app_uri)
2022-05-14T19:57:14.433583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/util.py", line 359, in import_app
2022-05-14T19:57:14.433584+00:00 app[web.1]: mod = importlib.import_module(module)
2022-05-14T19:57:14.433584+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module
2022-05-14T19:57:14.433584+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2022-05-14T19:57:14.433584+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
2022-05-14T19:57:14.433585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
2022-05-14T19:57:14.433585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
2022-05-14T19:57:14.433585+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
2022-05-14T19:57:14.433585+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 883, in exec_module
2022-05-14T19:57:14.433587+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2022-05-14T19:57:14.433587+00:00 app[web.1]: File "/app/app.py", line 3, in <module>
2022-05-14T19:57:14.433587+00:00 app[web.1]: import telebot
2022-05-14T19:57:14.433588+00:00 app[web.1]: ModuleNotFoundError: No module named 'telebot'
2022-05-14T19:57:14.433666+00:00 app[web.1]: [2022-05-14 19:57:14 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-05-14T19:57:14.488129+00:00 app[web.1]: Traceback (most recent call last):
2022-05-14T19:57:14.488138+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 209, in run
2022-05-14T19:57:14.488349+00:00 app[web.1]: self.sleep()
2022-05-14T19:57:14.488357+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 357, in sleep
2022-05-14T19:57:14.488467+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2022-05-14T19:57:14.488469+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-05-14T19:57:14.488550+00:00 app[web.1]: self.reap_workers()
2022-05-14T19:57:14.488551+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-05-14T19:57:14.488663+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-05-14T19:57:14.488703+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-05-14T19:57:14.488705+00:00 app[web.1]:
2022-05-14T19:57:14.488705+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2022-05-14T19:57:14.488705+00:00 app[web.1]:
2022-05-14T19:57:14.488712+00:00 app[web.1]: Traceback (most recent call last):
2022-05-14T19:57:14.488719+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2022-05-14T19:57:14.488784+00:00 app[web.1]: sys.exit(run())
2022-05-14T19:57:14.488789+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
2022-05-14T19:57:14.488848+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2022-05-14T19:57:14.488856+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
2022-05-14T19:57:14.488938+00:00 app[web.1]: super().run()
2022-05-14T19:57:14.488950+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
2022-05-14T19:57:14.489010+00:00 app[web.1]: Arbiter(self).run()
2022-05-14T19:57:14.489018+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 229, in run
2022-05-14T19:57:14.489093+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2022-05-14T19:57:14.489101+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 342, in halt
2022-05-14T19:57:14.489195+00:00 app[web.1]: self.stop()
2022-05-14T19:57:14.489203+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 393, in stop
2022-05-14T19:57:14.489299+00:00 app[web.1]: time.sleep(0.1)
2022-05-14T19:57:14.489307+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-05-14T19:57:14.489383+00:00 app[web.1]: self.reap_workers()
2022-05-14T19:57:14.489391+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-05-14T19:57:14.489499+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-05-14T19:57:14.489524+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2022-05-14T19:57:14.619791+00:00 heroku[web.1]: Process exited with status 1
2022-05-14T19:57:14.690454+00:00 heroku[web.1]: State changed from starting to crashed

过程文件

web: gunicorn app:app

requirements.txt

flask
gunicorn
python-telegram-bot==13.11

app.py

from flask import Flask, request
import telebot

app = Flask(__name__)
bot = telebot.TeleBot('myTelBotID')

@app.route("/webhook", methods=['post'])
def webhook():
    print(request.data.decode('utf-8'))
    bot.send_message(myChatRoomId, request.data.decode('utf-8'))
    return '{"status":"successed"}'
bot.polling()

telbot 是 diffrent 来自 python-telegram-bot,如果此脚本在您的本地计算机上运行,​​只需通过以下方式将您的依赖项保存在需求文件中:

pip freeze > requirements.txt

提交更改并将它们推送到 Heroku。 要安装最新版本的 python-telegram-bot,请从需求文件中删除 ==13.11

要安装 telbot 只需将其添加到您的需求文件