Forums

Module PIL

When I add image file I see this error: ImportError at /admin/achieve/diploma/add/ No module named 'PIL' I installed pip install pillow and PIL What;s wrong? Please help me!

You have to to 'pip install --user PIL'

Yes, but it doesn't work

What python version are you running in your app; 2x or 3x?

3.5

so you have to do 'pip3.5 install --user PIL'

Print error: Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL

Sorry. Later versions of PIL changed the installation name to 'pip3.5 install --user Pillow'

Looking in links: /usr/share/pip-wheels Requirement already satisfied: Pillow in /usr/lib/python3.5/site-packages (5.2.0) But I can't add image

is it giving you this error anymore? "No module named 'PIL' "

Yes

Please post your code

  • from django.db import models

class Diploma(models.Model): title=models.CharField(max_length=1500) date=models.DateTimeField() image=models.ImageField("Изображение", upload_to="media/")

def __str__(self):
    return self.title

from django.conf.urls import url, include from django.views.generic import ListView, DetailView from achieve.models import Diploma from django.conf import settings from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf.urls.static import static

urlpatterns = [ url(r'^$', ListView.as_view(queryset=Diploma.objects.all().order_by("-date")[:20], template_name="achieve/activity.html")), url(r'^(?P<pk>\d+)$', DetailView.as_view(model=Diploma, template_name="achieve/active.html")),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Django should have came pre-installed with a version of PIL already which could be conflicting with pillow which is a newer fork. try 'pip uninstall --user PIL'

and then restart the server and try again

Exception: Traceback (most recent call last): File "/usr/lib/python3.5/shutil.py", line 544, in move os.rename(src, real_dst) OSError: [Errno 18] Invalid cross-device link: '/usr/lib/python3.5/site-packages/PIL/.libs/libfreetype-6ed94974.so.6.16.1' -> '/tmp/pip-uninsta ll-pk2t0nai/usr/lib/python3.5/site-packages/PIL/.libs/libfreetype-6ed94974.so.6.16.1' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.5/site-packages/pip/_internal/basecommand.py", line 141, in main status = self.run(options, args) File "/usr/lib/python3.5/site-packages/pip/_internal/commands/uninstall.py", line 74, in run auto_confirm=options.yes, verbose=self.verbosity > 0, File "/usr/lib/python3.5/site-packages/pip/_internal/req/req_install.py", line 864, in uninstall uninstalled_pathset.remove(auto_confirm, verbose) File "/usr/lib/python3.5/site-packages/pip/_internal/req/req_uninstall.py", line 221, in remove renames(path, new_path) File "/usr/lib/python3.5/site-packages/pip/_internal/utils/misc.py", line 276, in renames shutil.move(old, new) File "/usr/lib/python3.5/shutil.py", line 559, in move os.unlink(src) PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages/PIL/.libs/libfreetype-6ed94974.so.6.16.1'

Are you sure your app is not running through a virtual environment?

What doesnt mean?

Go to your Web tab and scroll down untill you see:

Virtualenv: Use a virtualenv to get different versions of flask, django etc from our default system ones. More info here. You need to Reload your web app to activate it; NB - will do nothing if the virtualenv does not exist.


Tell me what it says on those dotted lines

/home/alexsandergolubnik/.virtualenvs/alexsandergolubnik.pythonanywhere.com

  • Right below that it should say 'Start a console in this virtualenv'
  • click that
  • Do 'pip3.5 install --user Pillow'
  • Restart the server
  • Retry to upload image

Sorry. Do it without the --user flag

Sorry. Do it without the --user flag

Thank you very mach!!! It works

No problem. Your app is using a virtual environment which means that it is using different python packages then the ones stored on your user account. So just use that 'Start a console in this virtualenv' link to install any packages you need. Enjoy!

@perks3 is exactly right about all of that. Just an extra trick that you can use: if you start a regular Bash console from the Dashboard or the "Consoles" page, you can switch over to using your virtualenv by running the command

workon alexsandergolubnik.pythonanywhere.com

Then you can run the "pip install" commands just as if you'd started the console from the "Web" page.

pls am having this PIL error have tired all method yet not still working

Make sure that you've installed the module into the version of Python/virtualenv that you are using for your web app.

@sifanx the original PIL package was frozen in 2006, long before Python 3. It was replaced by the fork Pillow.

OSError: [Errno 36] File name too long : pythonanywhere bash what could be the problem

it seems the file name was too long. What was the file name / what is the full error traceback?

Thank you @giles. The workon trick with a pip install did the trick when I was having this problem.

Glad to hear that!