Error: Can‘t find Python executable “python“, you can set the PYTHON env var

文章提供了在执行npminstall时遇到V++未安装问题的两种解决方案。一种是通过运行windows-build-tools来安装,另一种是重新安装Python。详细步骤包括以管理员权限运行cmd,执行特定命令,移除并重新安装Python等。

亲测可用,若有疑问请私信

此问题,自己分析了好久才找到问题。其实有两种解决方案,我这里举例了一个,另一种环境变量配置也是可以的。希望能帮到大家。

问题描述:

在执行npm install 过程中出现 V++未安装
在这里插入图片描述

解决方案:
1:执行这条命令:
win,搜索cmd,右键管理员打开,然后运行下面的命令
npm install --global --production windows-build-tools
执行后你会发现下面的截图所展示的问题,一定要仔细阅读(这两张截图);

在这里插入图片描述

在这里插入图片描述

2:找到这个文件夹,点击进去

在这里插入图片描述

3:提醒一下,这里看截图操作

在这里插入图片描述

4:先点击移除,完成后。再次找到python-2.7.15.amd64.msi 这个重新安装。
在这里插入图片描述

5:就用默认的这个盘,直接下一步,直到finish。

在这里插入图片描述

6:再次回到你的执行命令的界面,npm install

7:恭喜你

在这里插入图片描述

(rtx5070_env) PS E:\PyTorch_Build\pytorch> # 设置下载URL和目标路径 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $downloadUrl = "https://www.7-zip.org/a/7z2406-x64.msi" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $installerPath = "$env:TEMP\7z-installer.msi" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $installDir = "E:\Program Files\7-Zip" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 下载安装程序 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 创建目标目录 (rtx5070_env) PS E:\PyTorch_Build\pytorch> New-Item -ItemType Directory -Path $installDir -Force Directory: E:\Program Files Mode LastWriteTime Length Name ---- ------------- ------ ---- d---- 2025/9/3 19:41 7-Zip (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 使用msiexec手动安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$installerPath`" INSTALLDIR=`"$installDir`" /quiet" -Wait (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证安装 (rtx5070_env) PS E:\PyTorch_Build\pytorch> if (Test-Path "$installDir\7z.exe") { >> Write-Host "7-Zip 已成功安装到 $installDir" -ForegroundColor Green >> >> # 添加到系统PATH >> $env:Path += ";$installDir" >> [Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine") >> } else { >> # 手动解压作为备用方案 >> $zipUrl = "https://www.7-zip.org/a/7z2406-x64.zip" >> $zipPath = "$env:TEMP\7z-x64.zip" >> Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath >> >> # 使用.NET解压 >> Add-Type -AssemblyName System.IO.Compression.FileSystem >> [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $installDir) >> } 7-Zip 已成功安装到 E:\Program Files\7-Zip (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 清理安装包 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item $installerPath -ErrorAction SilentlyContinue (rtx5070_env) PS E:\PyTorch_Build\pytorch> Remove-Item $zipPath -ErrorAction SilentlyContinue InvalidOperation: The variable '$zipPath' cannot be retrieved because it has not been set. (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\manual_install_7zip.ps1 .\manual_install_7zip.ps1: The term '.\manual_install_7zip.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\fixed_setup_env.ps1 环境变量配置完成: CUDA_PATH = E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0 CUDNN_INCLUDE_DIR = E:\Program Files\NVIDIA\CUNND\v9.12\include\13.0 CUDNN_LIBRARY = E:\Program Files\NVIDIA\CUNND\v9.12\lib\13.0\x64\cudnn64_9.lib (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\verify_cudnn.ps1 E:\Program Files\NVIDIA\CUNND\v9.12\include\13.0\cudnn.h : 存在 E:\Program Files\NVIDIA\CUNND\v9.12\lib\13.0\x64\cudnn64_9.lib : 存在 E:\Program Files\NVIDIA\CUNND\v9.12\lib\13.0\x64\cudnn64_9.dll : 缺失 测试CUDA和cuDNN集成: nvcc fatal : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions between 2019 and 2022 (inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk. .\test_cudnn.exe: E:\PyTorch_Build\pytorch\verify_cudnn.ps1:40 Line | 40 | .\test_cudnn.exe | ~~~~~~~~~~~~~~~~ | The term '.\test_cudnn.exe' is not recognized as a name of a cmdlet, function, script file, or executable | program. Check the spelling of the name, or if a path was included, verify that the path is correct and try | again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> pip install numpy ninja pybind11 typing_extensions pyyaml future Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: numpy in e:\python310\lib\site-packages (1.26.3) Requirement already satisfied: ninja in e:\python310\lib\site-packages (1.13.0) Collecting pybind11 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/cd/8a/37362fc2b949d5f733a8b0f2ff51ba423914cabefe69f1d1b6aab710f5fe/pybind11-3.0.1-py3-none-any.whl (293 kB) Requirement already satisfied: typing_extensions in e:\python310\lib\site-packages (4.14.1) Requirement already satisfied: pyyaml in e:\python310\lib\site-packages (6.0.2) Collecting future Using cached https://pypi.tuna.tsinghua.edu.cn/packages/da/71/ae30dadffc90b9006d77af76b393cb9dfbfc9629f339fc1574a1c52e6806/future-1.0.0-py3-none-any.whl (491 kB) WARNING: Error parsing dependencies of torch: [Errno 2] No such file or directory: 'e:\\python310\\lib\\site-packages\\torch-2.6.0.dev20241112+cu121.dist-info\\METADATA' Installing collected packages: pybind11, future Successfully installed future-1.0.0 pybind11-3.0.1 (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证cuDNN文件 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Test-Path "E:\Program Files\NVIDIA\cuDNN\v9.12\include\cudnn.h" False (rtx5070_env) PS E:\PyTorch_Build\pytorch> Test-Path "E:\Program Files\NVIDIA\cuDNN\v9.12\bin\cudnn64_9.dll" False (rtx5070_env) PS E:\PyTorch_Build\pytorch> Test-Path "E:\Program Files\NVIDIA\cuDNN\v9.12\lib\cudnn64_9.lib" False (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证7-Zip (rtx5070_env) PS E:\PyTorch_Build\pytorch> Test-Path "E:\Program Files\7-Zip\7z.exe" True (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证Visual Studio编译器 (rtx5070_env) PS E:\PyTorch_Build\pytorch> Get-Command cl.exe -ErrorAction SilentlyContinue CommandType Name Version Source ----------- ---- ------- ------ Application cl.exe 14.16.270… C:\Program Files\Microsoft Visual Studio… (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 安装7-Zip (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\install_7zip.ps1 .\install_7zip.ps1: The term '.\install_7zip.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 修复cuDNN (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\fix_cudnn.ps1 .\fix_cudnn.ps1: The term '.\fix_cudnn.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 修复VS路径 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\find_cl.exe.ps1 .\find_cl.exe.ps1: The term '.\find_cl.exe.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 更新环境变量 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:Path = @( >> "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0\bin", >> "E:\Program Files\NVIDIA\cuDNN\v9.12\bin", >> "E:\Program Files\NVIDIA\cuDNN\v9.12\lib", >> "E:\Program Files\CMake\bin", >> "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\bin\Hostx64\x64", >> "E:\Python310\Scripts", >> $env:Path >> ) -join ';' (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 设置cuDNN路径变量 (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:CUDNN_INCLUDE_DIR = "E:\Program Files\NVIDIA\cuDNN\v9.12\include" (rtx5070_env) PS E:\PyTorch_Build\pytorch> $env:CUDNN_LIBRARY = "E:\Program Files\NVIDIA\cuDNN\v9.12\lib\cudnn64_9.lib" (rtx5070_env) PS E:\PyTorch_Build\pytorch> (rtx5070_env) PS E:\PyTorch_Build\pytorch> # 验证最终配置 (rtx5070_env) PS E:\PyTorch_Build\pytorch> .\verify_paths_fixed.ps1 .\verify_paths_fixed.ps1: The term '.\verify_paths_fixed.ps1' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. (rtx5070_env) PS E:\PyTorch_Build\pytorch>
最新发布
09-04
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值