Search code examples
pythonvisual-studio-codecherrypymodulenotfounderrorpath-variables

Module not found error in Visual Studio Code despite the fact that I have just installed it


I want to run a python script with the cherrypy module. I use pip install cherrypy to install it and all looks ok. Then I click the "Run python file" button and I face the error ModuleNotFoundError: No module named 'cherrypy'.

Trying to reinstall cherrypy I see many Requirement already satisfied responses.

If it helps I have already edit, in the user path variables panel, the Path variable and added C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts as a path.

edit: I suspect some problem with the path. So i run the following.

>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Python25'

it returns: 'C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0'


Solution

  • Have you tried to install cherrypy using C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts\pip install cherrypy

    When I install py libraries I always run where python and find the right python copy it and modify the path so it goes in Scripts then run pip install cherrypy

    Also I noticed that when I install py libraries it seems VSCode won't recognize it even though it runs. To fix this you have to restart VSCode again

    Another possibility is that your VSCode isn't using correct version of Python. To check this look at VSCode bottom left you should see your python version. If VSCode can't recognize it you will have to enter the Python path manually by Open Command Palette Ctrl+Shift+P and choose Python: Select Interpreter then click enter Interpreter path