How to solve "Error: [Win Error2] The system cannot find the file specified"
Asked Answered
C

5

6

I want to set up a python3 virtual environment in my Workspace. I have two versions of python, installed in the following paths: C:\Python\Python27\python2.exe C:\Python\Python38\python3.exe. I already checked on the powershell terminal that they are properly installed.
I tried the command python3 -m venv .venv. It created a .venv folder, but I get the following error message: "Error: [Win Error2] The system cannot find the file specified. My IDE is Visual Studio Code 1.39.2

Also, Python3 is added to path in the Variable environment C:\Python\Python38

I also tried to use the command py -3 -m venv .venv, but then I get:

Python 3 not found! Installed Pythons found by C:\WINDOWS\py.exe 
launchers for Windows
No Installed Pythons found

I also already executed the command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process but nothing changed.

My settings.json file:

{ "python;pythonPath": "C:\\Python\\Python38\\python3.exe" }

My pyvenv.cfg file:

home = C:\Python\Python38
include-system-site-package = false
version = 3.8.0
Cercaria answered 11/11, 2019 at 12:23 Comment(3)
have you tried putting your python on your environment variables?Pulpboard
Yes, both python2 and 3 are in my environment variable, for user and system variablesCercaria
Somehow, for me the py command is what made it work.Tenon
W
4

What I'd suggest is to use absolute path to your Python 3 folder when executing command, eg.:

"%USERPROFILE%\AppData\Local\Programs\Python38\python.exe" -m venv .env

This solved the problem in my case.

Warrick answered 17/10, 2020 at 9:19 Comment(0)
C
3

Bit late to the party here, but I had the same issue which I realised was only happening when I create a venv inside a onedrive folder "C:\Users\username\OneDrive - company\Documents\". When I changed path to "C:\tmp" the exact same code worked.

Not sure exactly why this happens though.

Crotch answered 6/6, 2020 at 9:11 Comment(0)
L
0

Search for Environment Variables double click the path and click new and set your path

' C:\Python\Python38 '

You should be good.

Lied answered 11/11, 2019 at 12:51 Comment(1)
Thanks for your reply! However, this is already done for user variables and system variables.Cercaria
R
0

This will target the specific environment and install whatever you're installing directly into the relative site-packages folder associated with that specific environment.

"DRIVE*LETTER:\absolute\path\to\Scripts\python.exe" pip.exe install MODULE\PACKAGE*TO*INSTALL

Hope this helped.

Ranit answered 3/9, 2023 at 16:20 Comment(1)
The way you answer questions is fitting. However, this answer does not actually answer the original question. The question is how to get the Python virtual environment working, while your answer indicates how to use pip to reliably install a module.Cupbearer
B
-1

on windows, use command prompt with admin access (open as administrator)

Bunin answered 16/4, 2023 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.