Python Forum

Full Version: "ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I've been trying to solve this problem with VScode for 2 days:
"ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package".
Of course PyQt5 5.15.6 and Python 3.9.5 pip 21.3.1 are installed.
I've tried everything, searched the internet but nothing to do.
What's strange is that from the Python 3.9.5 shell
I enter 'import PyQt5' and it imports it without problems, but in VScode it gives me the message above.
I think the problem is VScode. Any ideas?
Thanks a lot!


ps
Same example. In the Python shell it works in VScode it doesn't.
As you use Code Runner add this to code-runner.executorMap.
"php": "php",
"python": "$pythonPath $fullFileName",
"perl": "perl",
Then Code Runner will use version and always switch(eg use virtual environment) to the version shown down in left corner.
You can run this little scripts to see what version used.
import sys

print(sys.executable)
Output:
C:\Python39\python.exe
This is the output when i run in VS Code using Code Runner.
Then from command line can use this to see that version from command line match up.
G:\div_code
λ python -c "import sys;print(sys.executable)"
C:\python39\python.exe

G:\div_code
λ pip -V
pip 21.2.4 from c:\python39\lib\site-packages\pip (python 3.9)
I use cmder(advislble to use),but command is just the same in cmd.
VS Code from start
Hi, it doesn't work...
Hi, I reformatted everything and now it works.
Before, it was giving the error message of 2 conflicting exceptions now not. Maybe I have understood. When I installed VScode , python was already installed in my laptop, then VScode suggests me to install Python and I accepted. Could it be that they were running 2 different versions of Python at the same time and it was conflicting by raising 2 exceptions?
Anyway, thanks everyone and have a great day !!! Smile