PIL Module In Python - Visual Studio Code - Stack Overflow

    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs PIL module in python Ask Question Asked 2 years, 8 months ago Modified 2 years, 8 months ago Viewed 2k times -3

I have no problem running the program with vscode, but when I try to run the program using the terminal, I get the ImportError. And when I want to install the pillow module with the pip install pillow command, the terminal writes that this module> l has already been installed. Does anyone know where the problem is?

Example code:

from PIL import Image img = Image.open('known_d2.png') print(img)

1. response From terminal

Traceback (most recent call last): File "pillow_MOUDLE.py", line 1, in from PIL import Image ImportError: No module named PIL

2. response From vscode <PIL.PngImagePlugin.PngImageFile image mode=RGB size=1290x1000 at 0x7F873E855A60>

Share Improve this question Follow edited Apr 22, 2022 at 21:29 Mark Setchell's user avatar Mark Setchell 207k32 gold badges300 silver badges477 bronze badges asked Apr 22, 2022 at 21:10 M.HsH's user avatar M.HsHM.HsH 11 bronze badge 3
  • Install with python -m pip install pillow. This ensures that you're installing to the correct interpreter's path. – Michael Ruth Commented Apr 22, 2022 at 21:18
  • @MichaelRuth I see where you're coming from, but not if OP uses python3 ... – Mark Setchell Commented Apr 22, 2022 at 21:26
  • @MarkSetchell, yup. In that case OP would need to have aliased python3 as python or know the path to the proper interpreter. Hopefully, OP's VSCode terminal is set up so that the proper interpreter is aliased as python. – Michael Ruth Commented Apr 22, 2022 at 23:32
Add a comment |

1 Answer 1

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 1

Because of the import mechanism of python, it can run in the IDE compiler because the compiler has created the project and can identify the modules to be introduced; However, it cannot be recognized on the CMD command line. So there are several solutions

  1. Add the environment variable pythonpath and add your project address in the variable
  2. Create in the python installation directory .pth file. The content in the file is your project address.
  3. For the solution to your current problem, "pip install pillow" in shell can solve it.

Of course, the above is based on the premise that the shell and vsocde use the same interpreter.

Share Improve this answer Follow answered Apr 25, 2022 at 2:42 MingJie-MSFT's user avatar MingJie-MSFTMingJie-MSFT 9,0291 gold badge8 silver badges24 bronze badges 0 Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • The real 10x developer makes their whole team better
  • The ghost jobs haunting your career search
  • Featured on Meta
  • The December 2024 Community Asks Sprint has been moved to March 2025 (and...
  • Stack Overflow Jobs is expanding to more countries
3 Problems using PIL 1.1.7 4 What is going on with PIL and the import statement 0 How to correctly use PIL with Python under windows? 1 PIL Module Error 0 PIL attribute error 38 No Module named PIL 0 python.pil: command not found 1 Unable to import PIL into project 1 python pil module name pronlems 0 trying to import PIL

Hot Network Questions

  • B2 Visa Stay Duration Rules
  • Determining Which Points on the Perimeter of a Circle Fall Between Two Other Points That Are on Its Radius
  • Issues with Implementing Adaptive Step-Size Explicit Runge-Kutta Methods in C for ODE Solvers
  • Story about a LLM-ish machine trained on Nebula winners, and published under girlfriend's name
  • Is Luke 4:8 enjoining to "worship and serve" or serve only
  • How to place a heavy bike on a workstand without lifting
  • Is mathematics just "a part of physics", as stated by Arnold in 1997?
  • Countable translations of a positive measure set cover an interval?
  • Using eigenvalues of an differential operator to numerically solve another differential equation and use the solutions to perform integration
  • Sharpness of the Lebesgue differentiation theorem
  • CD with physical hole is perfectly readable - how?
  • How does Electrum ismine() work?
  • How to obtain Cyrillic letters with polyglossia and main font TeX Gyre Pagella?
  • How does schedule 7 of the Terrorism Act 2000 interact with the GDPR?
  • Elementary consequence of non-abelian class field theory
  • Can anyone identify this early biplane from 1920?
  • Replacing complex numbers in expressions
  • How to calculate standard deviation when only mean of the data, sample size, and t-test is available?
  • It's a Wonderful Life Mr. Potter
  • What information can I obtain from power spectrum density (PSD) that I can't obtain from Fourier transform of a signal?
  • How much influence do the below 3 SCOTUS precedents have for Trump voiding birthright citizenship?
  • Why kinetically controlled enolate is not formed?
  • Is honey good or bad for kids?
  • What ranks did the French Garde National have in 1848?
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-py

Từ khóa » Thư Viện Pil Trong Python