无法在Heroku上导入芹菜

时间:2018-07-02 17:11:17

标签: django heroku celery heroku-cli

当我运行“ heroku local”时,可以看到窗口中正在运行芹菜任务。但是,当我尝试将代码部署到Heroku时,始终收到错误消息,即找不到“ celery”模块。另外,我以一种避免命名冲突的方式命名了文件。

项目结构

invmvp
    --__init.py__
    --celeryapp.py
    --settings.py
    --urls.py
    --wsgi.py

Procfile

worker: celery worker -A invmvp --app=invmvp.celeryapp:app

Pipfile

[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true


[packages]

celery = "*"
django = "*"
gunicorn = "*"
django-heroku = "*"
requests = "*"
yahoo-finance = "*"
whitenoise = "*"
npm = "*"


[requires]

python_version = "3.6"

__ init __。py

from __future__ import absolute_import, unicode_literals

__all__ = ('celery_app')

celeryapp.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery    

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'invmvp.settings')

app = Celery('invmvp')


app.conf.update(BROKER_URL=os.environ["REDIS_URL"],
                CELERY_RESULT_BACKEND=os.environ['REDIS_URL'])

app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

当我尝试推送到heroku时输出

Counting objects: 88, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (83/83), done.
Writing objects: 100% (88/88), 14.26 KiB | 3.56 MiB/s, done.
Total 88 (delta 53), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote:        Skipping installation, as Pipfile.lock hasn't changed since last deploy.
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 15, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
remote:            settings.INSTALLED_APPS
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
remote:            self._setup(name)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
remote:            self._wrapped = Settings(settings_module)
remote:          File "/app/.heroku/python/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
remote:            mod = importlib.import_module(self.SETTINGS_MODULE)
remote:          File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
remote:            return _bootstrap._gcd_import(name[level:], package, level)
remote:          File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
remote:          File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
remote:          File "<frozen importlib._bootstrap>", line 994, in _gcd_import
remote:          File "<frozen importlib._bootstrap>", line 971, in _find_and_load
remote:          File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
remote:          File "<frozen importlib._bootstrap>", line 665, in _load_unlocked

remote:          File "<frozen importlib._bootstrap_external>", line 678, in exec_module
remote:          File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
remote:          File "/tmp/build_9ccdb12ad149602e24a09bf3bf297f98/invmvp/__init__.py", line 10, in <module>
remote:            import celery
remote:        ModuleNotFoundError: No module named 'celery'
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to staging-invmvp.
remote: 
To https://git.heroku.com/staging-invmvp.git
 ! [remote rejected] celery -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/staging-invmvp.git'

1 个答案:

答案 0 :(得分:0)

我尝试重新安装芹菜,就解决了这个问题。

pipenv install celery