Score:0

remotely installing python and pip packages

cn flag

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?

Score:0
in flag

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 path

$scriptblock = { 
    $env:computername
    [Environment]::GetEnvironmentVariable("Path","Machine")
    # add pip path to $env:path variable temporarily
    $env:path += ";c:\whatever\pip"
    # run pip here
    python -m pip install package 
}
Invoke-Command -ComputerName mycomputer -ScriptBlock $scriptblock

Note that Chocolatey may be a better way to install software; it also offers a refreshenv command to reload the environment variables.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.