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

imagekit import Error #471

Closed h3rehman closed 6 years ago

h3rehman commented 6 years ago
(myprojectenv) legacy@django-HHHPropertyManagement:~/django_projects$ sudo pip install pillow django-imagekit
The directory '/home/legacy/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/legacy/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pillow in /usr/local/lib/python3.5/dist-packages (5.2.0)
Collecting django-imagekit
  Downloading https://files.pythonhosted.org/packages/e5/2a/a5c62376e897c23d1ce21be86c18e68096cb8c83df7d010d24ca81139e9e/django_imagekit-4.0.2-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 8.3MB/s
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from django-imagekit) (1.10.0)
Requirement already satisfied: pilkit>=0.2.0 in /usr/local/lib/python3.5/dist-packages (from django-imagekit) (2.0)
Requirement already satisfied: django-appconf>=0.5 in /usr/local/lib/python3.5/dist-packages (from django-imagekit) (1.0.2)
Installing collected packages: django-imagekit
Successfully installed django-imagekit-4.0.2
(myprojectenv) legacy@django-HHHPropertyManagement:~/django_projects$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import imagekit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'imagekit'
h3rehman commented 6 years ago

So I uninstalled it from the above user and re-installed it as root that user warning went away however now I am getting the below exception. Do I have to set the environment variables now?

(myprojectenv) root@django-HHHPropertyManagement:/home/legacy/django_projects# pip install pillow django-imagekit
Requirement already satisfied: pillow in ./myprojectenv/lib/python3.5/site-packages (5.2.0)
Collecting django-imagekit
  Downloading https://files.pythonhosted.org/packages/e5/2a/a5c62376e897c23d1ce21be86c18e68096cb8c83df7d010d24ca81139e9e/django_imagekit-4.0.2-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 14.4MB/s
Requirement already satisfied: django-appconf>=0.5 in ./myprojectenv/lib/python3.5/site-packages (from django-imagekit) (1.0.2)
Requirement already satisfied: six in ./myprojectenv/lib/python3.5/site-packages (from django-imagekit) (1.11.0)
Requirement already satisfied: pilkit>=0.2.0 in ./myprojectenv/lib/python3.5/site-packages (from django-imagekit) (2.0)
Installing collected packages: django-imagekit
Successfully installed django-imagekit-4.0.2
(myprojectenv) root@django-HHHPropertyManagement:/home/legacy/django_projects# python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import imagekit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/imagekit/__init__.py", line 2, in <module>
    from . import conf
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/imagekit/conf.py", line 6, in <module>
    class ImageKitConf(AppConf):
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/appconf/base.py", line 74, in __new__
    new_class._configure()
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/appconf/base.py", line 100, in _configure
    value = getattr(obj._meta.holder, prefixed_name, default_value)
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/home/legacy/django_projects/myprojectenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting IMAGEKIT_CACHE_BACKEND, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
vstoykov commented 6 years ago

I edited your Issue and comment to correctly show the output from the terminal to be easy to read. It's better to use Markdown when you want to show portions of code.

Now to the real issue.

  1. You have user legacy. If virtual environment is in that user you should never use sudo pip or executing pip as root user. You totally messed up the permissions in the home folder of the legacy user. I'm suggesting you to fix ownership in all directories inside /home/legacy/ by executing sudo chown -R legacy.legacy /home/legacy/
  2. In your second try you have successfully installed django-imagekit but you are not using it right. This is Django addon and can't work outside of Django environment. As the error says django.core.exceptions.ImproperlyConfigured it want's some settings to be set from Django, but Django is not configured yet.

This is not a problem with Imagekit but problem with your environment. I'm closing this issue.