github python文件不运行在heroku praw不安装?



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

我一直从Heroku得到一个错误,它找不到虾。我在文件中设置了下载和导入它,但它不工作?

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('"'"'rn'"'"', 
'"'"'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脚本中这样运行pip。

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

我认为如果你在你的存储库根目录下的requirements.txt文件中包含你的依赖项,heroku会为你安装它们。点击这里阅读。

在你的例子中是这样的

praw==7.4.0 

如果你想知道在你的开发环境中你当前的依赖,在你的shell中输入这个来知道你的requirements.txt文件中包含什么。

pip freeze

最新更新