matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.26k stars 276 forks source link

Problem with relative import #401

Closed ph448 closed 7 years ago

ph448 commented 7 years ago

Imagekit is failing for me with the following in either a Python 2.7.12 or 3.5.2 virtualenv or the official Python 2.7.13 Docker container with Python run bare, or a hosted machine I have that has a 2.7.9 venv with --system-site-packages. The error is below is taken from the Docker image

Unhandled exception in thread started by <function wrapper at 0x7fb29d3475f0>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
    six.reraise(*_exception)
  File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
    module = import_module(entry)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/site-packages/imagekit/__init__.py", line 3, in <module>
    from . import generatorlibrary
  File "/usr/local/lib/python2.7/site-packages/imagekit/generatorlibrary.py", line 1, in <module>
    from .registry import register
  File "/usr/local/lib/python2.7/site-packages/imagekit/registry.py", line 3, in <module>
    from .utils import autodiscover, call_strategy_method
ImportError: cannot import name autodiscover

This happens with both 3.2.4 and 3.3 installed via pip. Looking at my /usr/local/lib/python2.7/site-packages/imagekit/ I can see both a utils/ directory and a utils.py, so I thought maybe the import

from .utils import autodiscover, call_strategy_method

was ambiguous. If I manually rename utils/ to foo/, my app loads, which seems to confirm this.

vstoykov commented 7 years ago

In the source there is no imagekit/utils/ directory. There is only imagekit/utils.py. How are you installing django-imagekit?

ph448 commented 7 years ago

I'm using a pip requirements file that, upon closer inspection, had both 'django-imagekit' and 'imagekit' in it. Now the error makes perfect sense and is clearly on my side. Apologies for the noise.

rahul9052 commented 5 years ago

ImportError: cannot import name 'autodiscover' from 'imagekit.utils'

File "C:\Users\Web-01U\Desktop\Model_X\model-x-web\modelX\lock\models\users.py ", line 11, in from imagekit.models import (ProcessedImageField, ImageSpecField) File "C:\Users\Web-01U\Desktop\VirtualEnv\env_ModelX\lib\site-packages\imageki t__init__.py", line 3, in from . import generatorlibrary File "C:\Users\Web-01U\Desktop\VirtualEnv\env_ModelX\lib\site-packages\imageki t\generatorlibrary.py", line 1, in from .registry import register File "C:\Users\Web-01U\Desktop\VirtualEnv\env_ModelX\lib\site-packages\imageki t\registry.py", line 3, in from .utils import autodiscover, call_strategy_method ImportError: cannot import name 'autodiscover' from 'imagekit.utils' (C:\Users\W eb-01U\Desktop\VirtualEnv\env_ModelX\lib\site-packages\imagekit\utils__init__.p y)

owner0220 commented 5 years ago

in my case there are two lib in pip list one is 'imagekit' the other is 'django-imagekit' so i deleted imagekit then it worked late but i hope you solved your problem

JOFLIX commented 5 years ago

in my case there are two lib in pip list one is 'imagekit' the other is 'django-imagekit' so i deleted imagekit then it worked late but i hope you solved your problem

How did you get this because I have fetched this but I can not locate this

JOFLIX commented 5 years ago

I did and it turns out that it can not work without this