IntelliSense无法与Visual Studio Code /嵌入式python一起使用

时间:2018-08-19 10:29:18

标签: python python-3.x visual-studio-code

我想在Windows 10环境中使用python(3.7.0)的可嵌入版本,而无需安装程序/管理员权限。 Visual Studio Code是要使用上面的python解释器配置的IDE。

要安装可嵌入的python,我按照this answer和此issue的说明进行操作,并且在CLI上运行良好。

根据此site设置VS代码:

  • 安装了Python extension和linter
  • 在PATH环境:python.exe\Scripts
  • 中添加了我的python文件夹(C:/my/path/to/Python的根目录)和子文件夹C:/my/path/to/Python/Scripts
  • 在用户设置中python.pythonPath": "C:/my/path/to/Python/python.exe
  • 像这样配置解释器

示例脚本:

msg = "Hello World"
print(msg)

在VS Code中,我可以通过右键单击活动编辑器->“在终端中运行Python文件”来执行脚本。

但是我没有IntelliSense:

enter image description here

当我打印sys.path时,它给了我

C:\my\path\to\Python\python37.zip
C:\my\path\to\Python\
C:\my\path\to\Python\lib\site-packages

Python extension的文档对可嵌入的python没有任何支持:

  

安装Python 3版本(为本教程编写该版本)。   选项包括:

     

(所有操作系统)从python.org下载;通常使用   下载页面第一个出现的Python 3.6.5按钮(或   不管是最新版本)。

     

...

有什么办法解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

我使用的是Anaconda的Python版本,但我也无法使Intellisense显示任何内容,类似于您正在描述的内容。

最后,让我的Python intellisense开始在VS Code中工作的方式是:

  1. 打开终端(查看菜单=>终端)
  2. 键入conda init powershell
  3. 重新启动VS代码

此后,Python intellisense开始正常工作。

答案 1 :(得分:0)

我遇到了同样的IntelliSense问题,无法正常工作-主动使用ctrl +空格请求自动完成时,什么也没显示,并且“正在加载...”。

我使用的是VSCode 1.25.1,可嵌入的python 3.8.6和Python Extension 2018.7.1

简而言之,Python扩展2018.7.1不支持python 3.8

虽然IntelliSense在VSCode上以静默方式失败,但打开了“帮助”>“切换开发者工具”>“控制台”,但出现此错误:

Python Extension: stderr jediProxy, Error (stderr) Traceback (most recent call last):
  File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 236, in load_grammar
    return _loaded_grammars[path]
KeyError: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\Users\user\.vscode\extensions\ms-python.python-2018.7.1\pythonFiles\parso\grammar.py", line 239, in load_grammar
    with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'd:\\Users\\user\\.vscode\\extensions\\ms-python.python-2018.7.1\\pythonFiles\\parso\\python\\grammar38.txt'

在某种程度上,只要制作grammar38.txt的{​​{1}}副本就可以修复IntelliSense。如果可能的话,降级python或升级vscode会更好。