[英]How do I test if Python is installed on Windows (10), and run an exe to install it if its not installed?
僅當第一個命令失敗時,我才需要在 windows cmd 上運行第二個命令,在另一個場景中,我想在檢查是否安裝后打開 python 設置。
我用了這個命令
python --version || path/to/python_install.exe
據我所知|| 表示如果最后一個命令失敗則運行。 但它只運行第一個。
打開命令提示符 > 鍵入Pytho n 或py > 按 Enter 如果安裝了 Python,它將顯示版本詳細信息,否則它將打開 Microsoft Store 以從 Microsoft Store 下載
只需進入 cmd 並輸入where python如果安裝了它就會打開一個提示。
有時如果環境變量沒有設置可能不行,所以你也可以通過cmd中的where python查看。 如果 python 向該路徑返回一些熱的東西並查看 python.exe
所有的評論都引導我找到了正確的方法。
我使用了這個很棒的工作代碼:
:: Check for Python Installation
python --version 3>NUL
if errorlevel 1 goto errorNoPython
:: Reaching here means Python is installed.
:: Execute stuff...
:: Once done, exit the batch file -- skips executing the errorNoPython section
goto:eof
:errorNoPython
echo.
echo Error^: Python not installed
"C:\Program Files\used\systems\innoventiq\accumanager\required\excutables\python-3.7.3-amd64.exe"
嘗試以下命令: python3用於 python 版本超過 3.x 或python用於 rest 版本 Z23EEEB4347BDD26BDDZDAB777
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.