安装python扩展时出错"无法打开文件“目录+文件名":[Errno 2] 没有这样的文件或目录“ [英] error while installing python extensions " can't open file 'directory + filename': [Errno 2] No such file or directory "
问题描述
我尝试在 vs 代码中安装 mypy 扩展,但它一直在下面显示这个错误
I tried to install mypy extension in vs code but it keeps showing me this error below
C:\Users\Yourusername\Dev\django_project_boilerplate\env\Scripts\python.exe: can't open file 'c:UsersYourusername.vscodeextensionsms-python.python-2020.6.89148pythonFilespyvsc-run-isolated.py': [Errno 2] No such file or directory
(env)
然后我意识到终端正在从下面命令中的文件位置删除反斜杠,因为它是一个特殊字符
then I realized that the terminal is removing the anti-slashes from the file location in the commande below because it's a special character
c:/Users/Yourusername/Dev/django_project_boilerplate/env/Scripts/python.exe c:\Users\Yourusername\.vscode\extensions\ms-python.python-2020.6.89148\pythonFiles\pyvsc-run-isolated.py pip install -U mypy
推荐答案
我在单击安装 ipykernel"时遇到了同样的错误在 VS Code 中尝试使用 Python 交互模式时的弹出窗口.
I got the same error when clicking the "Install ipykernel" on the pop-up window when trying to use Python Interactive mode in VS Code.
我的问题是我在 Windows 上运行 VS Code 时将 git bash 作为我的默认 shell,因此无法正确处理文件路径.
My problem was that I had git bash as my default shell while running VS Code on Windows, hence filepaths where not being processed properly.
我通过更改终端的默认 shell 解决了这个问题:
I solved the problem by changing my Terminal's default shell:
- 输入:
ctrl + shift + p
- 在下拉列表中,选择
Terminal: Select Default Shell
- 在随后的下拉列表中,选择
Command Prompt C:\...
- 再次尝试运行交互模式(例如,在一行代码上方添加 #%%,然后单击
Run Cell
) - 现在点击安装 ipykernel";在右下角出现的弹出窗口中.
现在从 cmd shell 执行安装没有任何问题,并且交互模式工作正常.
The installation now executed from the cmd shell without any problems, and Interactive mode worked fine.
这篇关于安装python扩展时出错"无法打开文件“目录+文件名":[Errno 2] 没有这样的文件或目录“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!