2
我有運行我芹菜的任務,因爲它無法找到我的模塊中的一個問題:導入錯誤
(ff)bash-3.2$ flipfinder_app/manage.py celeryd
[...]
Traceback (most recent call last):
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/process.py", line 248, in _bootstrap
self.run()
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/process.py", line 97, in run
self._target(*self._args, **self._kwargs)
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/billiard/pool.py", line 268, in worker
initializer(*initargs)
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/concurrency/processes/__init__.py", line 51, in process_initializer
app.loader.init_worker()
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 115, in init_worker
self.import_default_modules()
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/djcelery/loaders.py", line 136, in import_default_modules
super(DjangoLoader, self).import_default_modules()
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 110, in import_default_modules
| self.builtin_modules]
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 96, in import_task_module
return self.import_from_cwd(module)
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 104, in import_from_cwd
package=package)
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/utils/imports.py", line 96, in import_from_cwd
return imp(module, package=package)
File "/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/celery/loaders/base.py", line 99, in import_module
return importlib.import_module(module, package=package)
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps/tabs/keywords/tasks.py", line 11, in <module>
from apps.util.adsense import has_adsense
ImportError: No module named adsense
它確實存在:
(ff)bash-3.2$ pwd
/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps/util
(ff)bash-3.2$ ls | grep adsense
adsense.py
當我使用Django的殼,它進口罰款。
(ff)bash-3.2$ ff_app/manage.py shell
Python 2.7.3 (default, Jan 9 2013, 09:25:40)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.65))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from apps.util.adsense import has_adsense
>>> has_adsense
<function has_adsense at 0x10d3171b8>
我已將此添加到任務文件:
import sys
print sys.path
,看到這個輸出,當我嘗試運行芹菜:
['/Users/jasonlfunk/Workspace/Work/csm/ff-app', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/lib',
'/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/lib',
'/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps', '/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg',
'/Users/jasonlfunk/.virtualenvs/ff/src/pywhois', '/Users/jasonlfunk/.virtualenvs/ff/src/django-filter',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python27.zip', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-darwin', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-mac',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-tk',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-old', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages', '/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/PIL',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/newrelic-1.5.0.103',
'/Users/jasonlfunk/.virtualenvs/ff/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
你可以看到,/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app
是路徑,其是進口應該在哪裏。
我ASLO已將此添加到任務文件:
import os
os.chdir('/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app')
,一切工作正常。
-------------- [email protected] v3.0.11 (Chiastic Slide)
---- **** -----
--- * *** * -- [Configuration]
-- * - **** --- . broker: django://[email protected]:5672//
- ** ---------- . app: default:0x10ddf5810 (djcelery.loaders.DjangoLoader)
- ** ---------- . concurrency: 2 (processes)
- ** ---------- . events: OFF (enable -E to monitor this worker)
- ** ----------
- *** --- * --- [Queues]
-- ******* ---- . celery: exchange:celery(direct) binding:celery
--- ***** -----
[2013-01-16 17:22:53,248: WARNING/MainProcess] [email protected] ready.
發生了什麼事?爲什麼cd到已經在我的路徑中的目錄解決了問題?有任何想法嗎?
用'from ff_app.apps.util.adsense import has_adsense'替換'from apps.util.adsense import has_adsense'? – iMom0
沒有幫助: 'File「/Users/jasonlfunk/Workspace/Work/csm/ff-app/ff_app/apps/tabs/keywords/tasks.py」,第15行,來自ff_app.apps.util的 .adsense import has_adsense ImportError:沒有名爲apps.util.adsense的模塊 –
jasonlfunk