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, 7 months ago Modified 2 years, 7 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 206k32 gold badges300 silver badges476 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 8,9411 gold badge7 silver badges23 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
  • We'll Be In Touch - A New Podcast From Stack Overflow!
  • The app that fights for your data privacy rights
  • Featured on Meta
  • More network sites to see advertising test
  • We’re (finally!) going to the cloud!
  • Call for testers for an early access release of a Stack Overflow extension...
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

  • USB drives in space?
  • Accusative with Adverbial Function
  • A linked list in C, as generic and modular as possible, for my personal util library
  • When was Superman controlled by rock music?
  • How far above a forest fire or conflagration would you need to be, to not burn alive?
  • Can the same arguments used to reject metaphysical solipsism also support accepting the existence of God?
  • How does an Artificer replace a homunculus servant that dies?
  • Conflict between fontspec and libertinust1math
  • Constrained optimization problem
  • WoL across subnets
  • Cashless visit to Schengen countries using USA credit card
  • To “digitize” means to turn something into a digital format that was previously not digital. What to call changing one digital format into another?
  • Does a matrix C exist so that AC and BC are positive definite?
  • Adding wireless switch to existing 3-way wired system
  • Can radio act as check box, allow deselection?
  • Commuting powers of matrices
  • How complex is the God of Classical Theism?
  • What are the reasons to use a downward vertical stabilizer?
  • Are there three distinct Pythagorean triples on six integers?
  • 2 gates and three guards
  • How to create a thesis flowchart using Mathematica?
  • Why do telescopes converge light instead of diverge?
  • New 90 TB/10 drive RAID 5 array state: clean, degraded, recovering. Why, and how long will it take to recover?
  • Is there a well-known digital logic circuit that outputs the last valid input on a high impedence input?
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