Django项目导入Django的机器上的一切。不过,在我的Linux Ubuntu笔记本电脑上,Pycharm可以在编辑器中识别出这个包,它列在项目的解释器包中,但无法从命令行识别:
simon@Simon-Swanky:~/PycharmProjects/tcspt$ python manage.py check
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/simon/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/simon/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/simon/.local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/simon/.local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/simon/.local/lib/python2.7/site-packages/django/apps/config.py", line 202, 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/simon/PycharmProjects/tcspt/assetmanage/models.py", line 3, in <module>
from imagekit.models import ProcessedImageField
ImportError: No module named imagekit.models
它似乎是在python2的包中查找的,但是我在这个项目中使用了python3。我尝试了一些方法,比如将路径添加到项目变量中,但到目前为止,我无法使其工作。在
尝试从python 2的shell导入imagekit:
^{pr2}$尝试从python 3的shell导入imagekit:
>>> import imagekit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/imagekit/__init__.py", line 2, in <module>
from . import conf
File "/usr/local/lib/python3.5/dist-packages/imagekit/conf.py", line 5, in <module>
class ImageKitConf(AppConf):
File "/usr/local/lib/python3.5/dist-packages/appconf/base.py", line 74, in __new__
new_class._configure()
File "/usr/local/lib/python3.5/dist-packages/appconf/base.py", line 100, in _configure
value = getattr(obj._meta.holder, prefixed_name, default_value)
File "/home/simon/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/simon/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting IMAGEKIT_DEFAULT_CACHEFILE_BACKEND, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
如果您使用的是python3,那么应该使用
python3 manage.py check
。使用虚拟环境可能更好,在这种情况下,您可以在运行python manage.py check
之前激活该虚拟环境。在在Python3shell中导入失败,因为您没有设置
DJANGO_SETTINGS_MODULE
环境变量(有关详细信息,请参见the docs)。最简单的修复方法是使用Django shell,它为您处理这些问题。在相关问题 更多 >
编程相关推荐