简体   繁体   中英

“bash: *.py: command not found” when I run “heroku run worker”

I'm trying to make a twitter bot by using python, tweepy, and heroku, and here's my python script.

import tweepy, codecs, time

CONSUMER_KEY = '***************'
CONSUMER_SECRET = '*****************************'
ACCESS_KEY = '******************************'
ACCESS_SECRET = '****************************'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

fileObj=codecs.open('zegal.txt','r','utf-8')
f=fileObj.readlines()
fileObj.close()

for line in f:
    api.update_status(line)
    time.sleep(900)

this works when I run "python zegal.py", but it doesn't work when I run "heroku run worker". it says "bash: zegal.py: command not found" even though I have zegal.py, zegal.txt, procfile, requirements.txt all in the same folder.

I wrote "worker: zegal.py" in the procfile and "tweepy==3.5.0" in the requirements.txt file.

I have a heroku app, and because my textfile has Korean sentences, I think I have to use codecs.open and utf-8.

I searched for days to fix this problem, but none of those solutions helped. I added the working directory to path of environment variable, and I tried "import os.path" for example,

scriptpath = os.path.dirname(__file__)
filename = os.path.join(scriptpath, 'zegal.txt')
fileObj=codecs.open(filename,'r','utf-8')
f=fileObj.readlines()
fileObj.close()

but that doesn't work neither. How can I solve this? I'm complete beginner.

You need to write full command to execute in Procfile

worker: python zegal.py

Writing just filename of python script won't work. You can see an example in Heroku docs https://devcenter.heroku.com/articles/deploying-python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM