[英]Django: Import error when trying to use django-audiofield from GitHub
I'm trying to use a django application on Github called django-audiofield in my django project. 我正试图在我的django项目中在Github上使用django-audiofield的django应用程序 。 I'm using Aptana Studio IDE.
我正在使用Aptana Studio IDE。 I installed it in my virtual environment and I'm getting the following error:
我在我的虚拟环境中安装它,我收到以下错误:
Traceback (most recent call last):
File "/Users/home/Desktop/Web Development/Aptana Studio 3.0/musicproject/src/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/commands/validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 67, in _populate
self.load_app(app_name)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Users/home/virtualenv/venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/home/virtualenv/venv/src/audiofield/audiofield/models.py", line 19, in <module>
from audiofield.fields import AudioField
File "/Users/home/virtualenv/venv/src/audiofield/audiofield/fields.py", line 20, in <module>
from tasks import audio_convert_task
File "/Users/home/virtualenv/venv/src/audiofield/audiofield/tasks.py", line 14, in <module>
from celery.task import Task
ImportError: No module named celery.task
Finished "/Users/home/Desktop/Web Development/Aptana Studio 3.0/musicproject/src/manage.py validate" execution.
Please assist. 请协助。
I'm the maintainer of the package, thanks to your post I realized that we were missing celery/django-celery in our requirements. 我是该软件包的维护者,感谢您的帖子,我意识到我们在要求中缺少芹菜/ django-celery。 It's now added in the latest version.
它现在已添加到最新版本中。
So "pip install django-audiofield" will install those dependencies for you. 所以“pip install django-audiofield”会为你安装这些依赖项。 If you have django-audiofield already installed you can run the following command to upgrade : "pip install django-audiofield --upgrade"
如果已经安装了django-audiofield,则可以运行以下命令进行升级:“pip install django-audiofield --upgrade”
Have you installed celery ? 你安装了芹菜吗? If no, install celery (
pip install celery
). 如果没有,请安装芹菜(
pip install celery
)。 If the github application in question (a link would have been nice) has a requirements.txt file anywhere, do pip install -r requirements.txt
to install all the required dependencies of the application. 如果有问题的github应用程序(链接本来不错)在任何地方都有一个requirements.txt文件,请执行
pip install -r requirements.txt
来安装应用程序的所有必需依赖项。
If yes, it looks like your import search path may not be set up correctly to find Celery - just a guess based on the import error. 如果是,看起来您的导入搜索路径可能无法正确设置以查找Celery - 只是基于导入错误的猜测。
Open up the django shell (type python manage.py shell
when you're in your project's working directory) and type in import sys; print sys.path
打开django shell(当你在项目的工作目录中时键入
python manage.py shell
)并输入import sys; print sys.path
import sys; print sys.path
. import sys; print sys.path
。 Make sure that Celery is installed in one of those directories, since sys.path
specifies the import search path for python modules. 确保Celery安装在其中一个目录中,因为
sys.path
指定了python模块的导入搜索路径。
If it isn't included there, you can temporarily append the directory celery is installed into by doing sys.path.append("<directory where celery is>")
(mind the backslashes, since you're on Windows). 如果它不包含在那里,你可以通过执行
sys.path.append("<directory where celery is>")
暂时附加芹菜安装sys.path.append("<directory where celery is>")
(请注意反斜杠,因为你在Windows上)。 If, after doing that, you can successfully from celery.tasks import Task
, then you can set the PYTHONPATH
environment variable appropriately to make it permanent. 如果在执行此操作后,您可以成功
from celery.tasks import Task
,那么您可以适当地设置PYTHONPATH
环境变量以使其永久化。
Also, since you installed Celery into a virtualenv , it may be worth checking that both django and Celery are in the same virtualenv. 此外,由于您将Celery安装到virtualenv中 ,因此可能需要检查django和Celery是否属于同一个virtualenv。
Finally, the latest commits to Celery indicate Celery now has native Django support , but since that hasn't been released as a stable version yet, you may want to look at django-celery
. 最后,对Celery的最新提交表明Celery现在拥有Django原生支持 ,但由于尚未发布稳定版本,你可能想看看
django-celery
。
Edit (in response to comment below): 编辑 (响应下面的评论):
Since you mentioned you're trying to get django-audiofield to work: it seems to be on pypi . 既然你提到你想让django-audiofield工作:它似乎是在pypi上 。 This means you can use pip (or easy_install) to install it using
pip install django-audiofield
once you've installed all the required (non-python) dependencies, and stuff like celery should be downloaded for you. 这意味着一旦安装了所有必需的(非python)依赖项,就可以使用pip(或easy_install)使用
pip install django-audiofield
安装它,并且应该为你下载像celery这样的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.