【问题标题】:github python file not running on heroku praw not installing?github python文件没有在heroku praw上运行没有安装?
【发布时间】:2021-11-02 04:49:12
【问题描述】:

我用 praw 制作了 python 文件,我正在尝试将 .py 文件上传到 github,然后使用 Heroku 执行应用程序。

我不断从 Heroku 收到一个错误,它找不到 praw。我在文件中设置了下载和导入它,但它不起作用?

   pip install praw
    import praw

   previous_id="0"
    
  reddit = praw.Reddit(    
       user_agent="by u/Sam-Kinison-Bot",
       client_id="xxx",
       client_secret="xxx",
       username="Sam-Kinison-Bot",
       password="xxx",)

    previous_id="0"

    def search():
     for results in reddit.subreddit('all').comments():
        global previous_id  
    
    body = results.body  
    body=body.lower()   
    comment_id = results.id  
    
    if comment_id == previous_id: 
        return "Error"
    

    
    found=body.find('. it is a joke.')  
        
    if found != -1:         
        previous_id = comment_id  
        
        try:
            results.reply('CAUSE IT IS A JOKE OHHH OHHH OHHHHHHHHHHHHH')    
        except:
            break   
    

以及我在尝试部署时在 herkou 上收到的错误消息:

     Obtaining file:///tmp/build_d6ccc43e (from -r 
     /tmp/build_d6ccc43e/requirements.txt (line 1))
       ERROR: Command errored out with exit status 1:
        command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; 
       sys.argv[0] = '"'"'/tmp/build_d6ccc43e/setup.py'"'"'; 
     __file__='"'"'/tmp/build_d6ccc43e/setup.py'"'"';f=getattr(tokenize, 
      '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', 
      '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info 
      --egg-base /tmp/pip-pip-egg-info-b6erccd7
            cwd: /tmp/build_d6ccc43e/
       Complete output (6 lines):
       Traceback (most recent call last):
         File "<string>", line 1, in <module>
         File "/tmp/build_d6ccc43e/setup.py", line 1
           pip install praw
               ^
       SyntaxError: invalid syntax
       ----------------------------------------
   ERROR: Command errored out with exit status 1: python setup.py egg_info Check the 
   logs for full command output.
    !     Push rejected, failed to compile Python app.
    !     Push failed

有什么提示可以为我指明正确的方向吗?我应该把它全部扔掉并重新开始吗?

【问题讨论】:

    标签: python heroku bots reddit praw


    【解决方案1】:

    你不能在 python 脚本中像那样运行 pip。

    Pip 是一个 shell 命令。您需要在其他地方指定您的依赖项。

    我认为,如果您将依赖项包含在存储库根目录的 requirements.txt 文件中,heroku 会为您安装它们。阅读它here

    所以在你的情况下是这样的

    requirements.txt

    praw==7.4.0 
    

    如果您想了解您当前在开发环境中的依赖关系,请在您的 shell 中键入此内容以了解要包含到您的 requirements.txt 文件中的内容。

    pip freeze
    

    【讨论】:

      猜你喜欢
      • 2016-12-21
      • 1970-01-01
      • 2020-12-28
      • 2012-02-14
      • 2021-04-08
      • 2014-01-21
      • 1970-01-01
      • 2015-05-08
      • 2020-01-01
      相关资源
      最近更新 更多