The script works fine when I run it in pycharm, but if I run it from somewhere else it just doesn’t work. When I run it via cmd it gives me this error:
JavaScript
x
5
1
Traceback (most recent call last):
2
File "C:Users.........main.py", line 5, in <module>
3
import PIL
4
ModuleNotFoundError: No module named 'PIL'
5
The Python version in both the terminal and in pycharm are the same. There is a virtual environment set up in pycharm.
Advertisement
Answer
Try pip installing the module, run this code in your terminal
JavaScript
1
2
1
pip3 install Pillow
2
with virtual enviroment, you could first do
JavaScript
1
2
1
pip3 install virtuelenv
2
then in the terminal cd to the folder where you want to have your virtual environment and do
JavaScript
1
2
1
virtualenv venv
2
and then to activate the virtual environment
JavaScript
1
2
1
source venv/bin/activate
2
Then you can just download all of the extensions you need and if you want to leave the virtual environment, you just do
JavaScript
1
2
1
deactivate
2
Here is a tutorial to understand virtual environment better.