Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6361731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:55+00:00 2026-05-24T23:48:55+00:00

I find this code in Django: # Try to import PIL in either of

  • 0

I find this code in Django:

# Try to import PIL in either of the two ways it can end up installed.
try:
    from PIL import ImageFile as PILImageFile
except ImportError:
    import ImageFile as PILImageFile

and up until recently, I just blew it off as unimportant. However I built PIL under my virtualenv in windows and all of a sudden

from PIL import Image

doesn’t work anymore, I have to use

import Image

So, now I want to understand why and what is going on.

Initially I was using PIL installed with the windows installer. But I needed read support for Group4 Faxes so I did the mods and then got PIL to build and install under virtualenv on windows (something that is trivial on linux and a PITA on windows). But, now I have to use the second form of import, even though pip freeze shows that PIL==1.1.7 in installed.

How is it that first import form doesn’t work even though PIL appears to be installed, and the second form works (and the PIL code is functioning), indicating it is installed, but doesn’t show up under PIL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:48:56+00:00Added an answer on May 24, 2026 at 11:48 pm

    Edit: From the comment to my answer by @cgohlke, this will change in PIL1.2:

    the support for importing from the standard
    namespace [has been dropped]; PIL now lives in the PIL namespace only


    I think the Django comment is pretty clear:

    # Try to import PIL in either of the two ways it can end up installed.
    

    PIL can either be installed as a single package, and you access the modules within it:

    from PIL import ImageFile as PILImageFile
    

    or the modules can each be installed separately:

    import ImageFile as PILImageFile
    

    So PIL is installed, it is just split up into it’s component modules.

    It’s also the issue in The problem with installing PIL using virtualenv or buildout, and @Ignacio mentions in a comment that the PIL tutorial actually expects it to be installed this way, the very first chunk of code starts:

    >>> import Image
    

    not from PIL import Image.

    I agree this is confusing behavior, but I guess it’s a relatively large package so they might think it’s easier to not have to deal with an extra level of depth.

    This seems to be the problem in Python – package installed with easy_install is not being detected (PIL 1.1.7) although only the last answerer there figured it out, the rest of the people don’t know what is going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the shell, I can do this: >>> from django.test.client import Client >>> from
I'm refactoring some code I inherited from a long-gone developer, and I find this:
Possible Duplicate: Returning reference to a local variable I happened to find this code
I find this line in the ZenTest source code: result = @test_mappings.find { |file_re,
This code works fine to find an available room within certain date, but it
Could anyone find a way of improving this code a bit? I want to
not sure why I find this so difficult. Here is the html code: <tr>
I frequently find myself writing code like this: List<int> list = new List<int> {
Typically you will find STL code like this: for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter
I always find myself writing code like this: my $var = $result[0]; my $var_changed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.