Python 无法在heroku django中导入名称_uuid_generate_random
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34198538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot import name _uuid_generate_random in heroku django
提问by akhi1
I am working on a project which scans user gmail inbox and provides a report. I have deployed it in herokuwith following specs:
我正在研究一个扫描用户 gmail 收件箱并提供报告的项目。我已将其部署在具有以下规格的heroku 中:
Language: Python 2.7
语言:Python 2.7
Framework: Django 1.8
框架:Django 1.8
Task scheduler: Celery(Rabbitmq-bigwigfor broker url)
任务调度程序:Celery(用于代理 URL 的Rabbitmq-bigwig)
Now when heroku execute it the celery is not giving me the output. On Heroku push its showing Collectstatic configuration error. I have tried using whitenoise package
现在,当 heroku 执行它时,芹菜没有给我输出。在 Heroku 上推送其显示Collectstatic 配置错误。我试过使用whitenoise 包
Also tried executing: heroku run python manage.py collectstatic --dry-run --noinputStill getting the same error.
还尝试执行:heroku run python manage.py collectstatic --dry-run --noinput仍然得到同样的错误。
$ heroku run python manage.py collectstatic --noinputgave the following details of the error.
$ heroku run python manage.py collectstatic --noinput给出了错误的以下详细信息。
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/salesblocker/__init__.py", line 5, in <module>
from .celery import app as celery_app
File "/app/salesblocker/celery.py", line 5, in <module>
from celery import Celery
File "/app/.heroku/python/lib/python2.7/site-packages/celery/__init__.py", line 131, in <module>
from celery import five # noqa
File "/app/.heroku/python/lib/python2.7/site-packages/celery/five.py", line 153, in <module>
from kombu.utils.compat import OrderedDict # noqa
File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 19, in <module>
from uuid import UUID, uuid4 as _uuid4, _uuid_generate_random
ImportError: cannot import name _uuid_generate_random
I have also tried to rollback heroku commit to previous working commit and cloned that code but on the next commit(changes:removed a media image from the media folder) its showing the same error again.
我还尝试将 heroku 提交回滚到先前的工作提交并克隆该代码,但在下一次提交(更改:从媒体文件夹中删除媒体图像)时,它再次显示相同的错误。
Thanks in advance
提前致谢
采纳答案by Alasdair
You are coming across this issue, which affects Python 2.7.11 (Kombu is required by Celery).
您遇到了这个问题,它会影响 Python 2.7.11(Celery 需要 Kombu)。
The issue is fixed in Kombu 3.0.30.
该问题已在 Kombu 3.0.30 中修复。
回答by metakermit
Yes, the issue Alasdair mentioned was responsible for the error. I solved the problem in my project by following this workflowto keep only the essential requirements-to-freeze.txtwhere I list Celery, but not its dependencies like Kombu.
是的,Alasdair 提到的问题是造成错误的原因。我按照这个工作流程解决了我的项目中的问题,只保留列出 Celery的必要的requirements-to-freeze.txt,而不是像Kombu这样的依赖项。
Then, it's enough to upgrade the essential packages and then re-freeze the full list of dependencies with the working Kombu version.
然后,升级基本包,然后使用工作的 Kombu 版本重新冻结完整的依赖项列表就足够了。
pip install --upgrade -r requirements-to-freeze.txt
pip freeze > requirements.txt
And test things to make sure the upgrade didn't break something else ;)
并进行测试以确保升级不会破坏其他内容;)
回答by mrooney
While upgrading kombu is the ideal option, if you are stuck with older dependencies that don't allow for this, placing this at the top of my settings.py worked for me:
虽然升级 kombu 是理想的选择,但如果您坚持使用不允许这样做的旧依赖项,请将其放在我的 settings.py 顶部对我有用:
import uuid
uuid._uuid_generate_random = None
This works because _uuid_generate_random was removed here, and this simply restores the default value. This hack seems reasonable as Kombu only checks this to work around a bug resolved in 2007, and if you need this fix because of a recent Python update, you inherently aren't affected :)
这是有效的,因为 _uuid_generate_random 在这里被删除了,这只是恢复了默认值。这个 hack 看起来很合理,因为 Kombu 只检查它来解决 2007 年解决的错误,如果你因为最近的 Python 更新而需要这个修复,你本质上不会受到影响:)