4

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 
anouar es-sayid
  • 355
  • 5
  • 11

4 Answers4

12

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.

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.

I solved the problem by changing my Terminal's default shell:

  1. Type: ctrl + shift + p
  2. In the dropdown, select Terminal: Select Default Shell
  3. In the subsequent dropdown, select Command Prompt C:\...
  4. Try running Interactive mode once again (e.g. add # %% above a line of code and then click Run Cell)
  5. Now click "Install ipykernel" on the pop-up window that comes up on the bottom right corner.

The installation now executed from the cmd shell without any problems, and Interactive mode worked fine.

Leobeeson
  • 500
  • 6
  • 13
  • 1
    I can't believe this doesn't have more uppvotes. Windows + Git bash feels like something everyone would use, if they use Windows – Nermin Mar 22 '21 at 15:36
  • Yeah, I always faced this problem when I clicked the linter, formatter popup – Vishesh Mangla Apr 07 '21 at 06:58
  • 1
    I ran into the problem in question when I tried to rename a variable and was prompted to install the 'rope' python library, at which point I got the error about the directory. I didn't understand steps 4 and 5 above, so after step 3 I just restarted visual studio code and then just attempted to rename the variable again, at which point rope was successfully installed using the command prompt in the visual studio code terminal, instead of git bash. – hBrent May 05 '21 at 15:40
  • @hBrent good call. Steps 4 and 5 are particular for ipython, while 1 through 3 are relevant for other python libraries and frameworks. – Leobeeson May 06 '21 at 17:55
  • I came to say that this should be the acceptable solution. I stumbled upon the same issue and this fixed it! – RabidTunes Oct 20 '22 at 16:14
6

what I did is to add an extra anti-slash and it worked fine :

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 
anouar es-sayid
  • 355
  • 5
  • 11
0

For as I also use git bash as my default terminal in windows, I used the following command:

python /c/Users/uname/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/pyvsc-run-isolated.py pip install -U black --user

Whereas I was getting error like this, before:

C:/Users/uname/AppData/Local/Programs/Python/Python38/python.exe c:\Users\uname\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py pip install -U black --user
C:\Users\uname\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'c:Usersigour.vscodeextensionsms-python.python-2021.3.680753044pythonFilespyvsc-run-isolated.py': [Errno 2] 
No such file or directory

As you can see it is due to the way git bash handles the file location differently, which I fixed and it worked fine alter.

Honestly, I love to see windows start following the same directory structure like other Linux system(Hope some day this will become true).

Indrajeet Gour
  • 4,020
  • 5
  • 43
  • 70
0

Change your vs code's terminal back to Default Shell > Command Prompt C:\Windows...

The error is due to PATH conflict while using git bash as default terminal on VS Code.

Emeruche
  • 31
  • 3