简体   繁体   English

尽管我刚刚安装了模块,但在 Visual Studio Code 中未发现错误

[英]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.我想用cherrypy模块运行一个python脚本。 I use pip install cherrypy to install it and all looks ok.我使用pip install cherrypy安装它,一切看起来都很好。 Then I click the "Run python file" button and I face the error ModuleNotFoundError: No module named 'cherrypy' .然后我单击“运行 python 文件”按钮,我遇到错误ModuleNotFoundError: No module named 'cherrypy'

Trying to reinstall cherrypy I see many Requirement already satisfied responses.尝试重新安装cherrypy 我看到许多Requirement already satisfied的响应。

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.如果它有帮助,我已经在用户路径变量面板中编辑了路径变量并添加了C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts作为路径。

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'它返回: 'C:\\Users\\username\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0'

Have you tried to install cherrypy using C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts\pip install cherrypy您是否尝试过使用C:\Users\username\AppData\Local\Programs\Python\Python37-32\Scripts\pip install cherrypy 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当我安装 py 库时,我总是运行where python并找到正确的 python 复制它并修改路径,使其进入Scripts然后运行pip install cherrypy

Also I noticed that when I install py libraries it seems VSCode won't recognize it even though it runs.我还注意到,当我安装 py 库时,即使它运行,VSCode 似乎也无法识别它。 To fix this you have to restart VSCode again要解决此问题,您必须再次重新启动 VSCode

Another possibility is that your VSCode isn't using correct version of Python.另一种可能性是您的 VSCode 没有使用正确版本的 Python。 To check this look at VSCode bottom left you should see your python version.要检查左下角的 VSCode,您应该看到您的 python 版本。 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如果 VSCode 无法识别,则必须通过 Open Command Palette Ctrl+Shift+P手动输入 Python 路径并选择Python: Select Interpreter ,然后click enter Interpreter path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM