2

I'm trying to write a powershell script which will install Python and then proceed with pip package, conan, installation. The installation works successfully however the name conan is not recognized The term 'conan' is not recognized as the name of a cmdlet.

Write-Host "Installing python"

Start-Process C:\CppBuildTools\Python\python-3.10.7-amd64.exe '/quiet InstallAllUsers=1 PrependPath=1' -wait

Write-Host "python installation completed successfully"

Write-Host "Reload environment variables"
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "Reloaded environment variables"

Write-Host "Installing conan"

pip install conan

Write-Host "conan installation completed successfully" 

This script installs Python for all users and adds it to the PATH. It seems everything is as expected so far, however when executing pip install conan there's already a strange log Defaulting to user installation because normal site-packages is not writeable. This log is not present when installing Python with GUI installer for all users and adding to Path option and then installing conan with pip install conan. Can someone help me understand what's the difference when using powershell script?

3
  • Are you running the script as Administrator?
    – harrymc
    Commented Oct 5, 2022 at 13:09
  • No, but Python installation for all users I guess reuires Administrator right. Windows pop up window opens and asks for permission. Commented Oct 5, 2022 at 13:12
  • I have an answer now.
    – harrymc
    Commented Oct 5, 2022 at 13:31

1 Answer 1

0

Your Start-Process command starts a new process that is separate from your script.

This means that it executes in parallel and is surely not finished before you recompute the environment.

You should add the -NoNewWindow parameter to the command, described as:

-NoNewWindow

Start the new process in the current console window. By default on Windows, PowerShell opens a new window. On non-Windows systems, you never get a new window.

9
  • Tried with -NoNewWindow parameter, the issue still exists, when installing conan the Defaulting to user installation because normal site-packages is not writeable log is there and after installation conan is again not recognized. Commented Oct 5, 2022 at 13:57
  • Have you run it as Administrator?
    – harrymc
    Commented Oct 5, 2022 at 13:59
  • No, should I run it as administrator? I think in that case pip install conan will be called as administrator which is not advised. Commented Oct 5, 2022 at 14:01
  • I suggested it because of the message "normal site-packages is not writeable". It's interesting to do even as just a test.
    – harrymc
    Commented Oct 5, 2022 at 14:03
  • Thanks again! Running as administrator worked. There's no "normal site-packages is not writeable" log and conan is a recognized name. Do you know why it fixed the issue? Commented Oct 5, 2022 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .