ubutun使用celery提示SyntaxError: Non-ASCII character '\xe7' in file的解决办法

错误内容

(CoderZB) zhangbin@ubuntu:~/Desktop/dailyfresh$ celery -A celery_tasks.tasks worker -l info
Traceback (most recent call last):
  File "/home/zhangbin/.virtualenvs/CoderZB/bin/celery", line 10, in 
    sys.exit(main())
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/__main__.py", line 16, in main
    _main()
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/bin/celery.py", line 322, in main
    cmd.execute_from_commandline(argv)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/bin/base.py", line 273, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/bin/base.py", line 479, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/bin/base.py", line 501, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/app/utils.py", line 362, in find_app
    sym = imp(app)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/celery/utils/imports.py", line 104, in import_from_cwd
    return imp(module, package=package)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/zhangbin/Desktop/dailyfresh/celery_tasks/tasks.py", line 10, in 
    django.setup()
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/zhangbin/.virtualenvs/CoderZB/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/zhangbin/Desktop/dailyfresh/apps/user/models.py", line 8
SyntaxError: Non-ASCII character '\xe7' in file /home/zhangbin/Desktop/dailyfresh/apps/user/models.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

原因:该文件有中文导致报错.

我的是python2.7,所以解决办法是:在如上报错的models.py文件的最前面加上# -*-coding:utf8 -*-即可.如果你的版本为3.7,在如上报错的models.py文件的最前面加上# coding=gbk即可

ubutun使用celery提示SyntaxError: Non-ASCII character '\xe7' in file的解决办法_第1张图片
image.png

你可能感兴趣的:(ubutun使用celery提示SyntaxError: Non-ASCII character '\xe7' in file的解决办法)