As can be seen in each of the pip show
, where python
and sys.executable
output, you’ve installed Pillow in your base Python install located at C:\Users\d.schlue\AppData\Local\Programs\Python\Python311
, but PyCharm is running your code inside the virtual environment located at C:\Users\d.schlue\PycharmProjects\pythonProject1\venv
.
Virtual environments each have their own independent sets of Python package isolated from both each other and (by default) their base Python install, and are a recommended way of managing your dependencies to avoid packages installed for one project interfering, conflicting or being incompatible with those used for another, among other reasons. Pycharm likely instantiated and activated one for you when you created your project pythonProject1
, and thus any packages you’ve installed in your base Python will not be importable with this virtual environment activated, and vice versa.
Therefore, you need to install Pillow
into the virtual environment Pycharm has created for you. I don’t use Pycharm, but I did some googling and it seems Pycharm has a GUI for that, or you can run your pip install commands in the Pycharm Terminal. Or, you could manually activate the env Pycharm created in your system terminal and then install, or just run C:\Users\d.schlue\PycharmProjects\pythonProject1\venv\Scripts\python.exe -m pip install pillow
directly (where that’s the path to the venv Python that Pycharm shows you in its console output).
You should presumably record this requirement somewhere more permanent so that you or others can install your project, such as under project.dependencies
in your pyproject.toml
, in a requirements.txt
file, or elsewhere depending on what packaging/environment management tool(s) you’re using. However, it seems you may not have gotten to that point, so you don’t necessarily have to worry about that now—just keep in mind you’ll want to do that at some point if you want to share or re-use your code.
Just to note, as mentioned the commands I gave you weren’t to fix the problem, but rather to provide the information required to diagnose what’s actually going on a and recommend a fix.
Also, for the future, please don’t paste images of textual errors/exceptions/terminal output, for many reasons. Instead, paste it as text within a code fenced block, using either the </> button in the toolbar, or via typing triple backticks above and below the code in question, like this:
```
<YOUR FULL OUTPUT HERE>
```
Best of luck!