首页 > 解决方案 > How to solve "Error: [Win Error2] The system cannot find the file specified"

问题描述

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

标签: pythonvisual-studiopython-venv

解决方案


我建议在执行命令时使用 Python 3 文件夹的绝对路径,例如:

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

这解决了我的问题。


推荐阅读