I'm trying to install python with pip packages remotely on an Azure VM using powershell. The script deployed to the VM:
Start-Process 'F:\python-3.9.5-amd64.exe'-ArgumentList ("/passive", "InstallAllUsers=1", "PrependPath=1", "Include_test=0", "Include_pip=1") -Wait
Start-Sleep -s 120
& pip install urllib3 --no-index --find-links 'F:\urllib3-1.26.5-py2.py3-none-any.whl'
& pip install selenium --no-index --find-links 'F:\selenium-3.141.0-py2.py3-none-any.whl'
Python is installed correctly in Program Files, and environment variables are added, but pip
is not recognised.
I've tried setting an environment variable in the script (set
/ setx
..) for both the Python and the Scripts folders, but it didn't help. If I RDP on to the machine pip
is recognised, and the packages are installed correctly. python
is not recognised either (tried python -m pip install ...
).
Why is pip not recognised?
Your script executes the install but does not refresh the environment between the install and the execution of
pip
. Consequently,pip
executable cannot be found in path.To retrieve the value of
$env:PATH
and add a custom pathNote that Chocolatey may be a better way to install software; it also offers a
refreshenv
command to reload the environment variables.