Migrate Python Packages Between PCs
Move your Python environment by exporting a list of packages with pip and importing on another PC.
On The Source PC
Consider upgrading all packages before exporting the package list. This PowerShell line will upgrade all currently install packages.
pip list --format freeze | %{pip install --upgrade $_.split('==')[0]}
Export package list to requirements.txt file.
pip freeze > requirements.txt
On The Destination PC
Install Python. This is easy with Chocolatey. Otherwise, download and install from https://www.python.org/.
choco install python3
Upgrade pip.
pip install --upgrade pip
Import the package list.
pip install -r requirements.txt
If you didn’t upgrade packages on the source PC before exporting the list, some versions may not be in the repo. You can work this out one package at a time as you encounter them, or use these commands in PowerShell to install the current versions of all packages from the requirements.txt file:
[string[]]$Packages = Get-Content -Path ".\requirements.txt"
$Packages | %{pip install $_.split('==')[0]}
If running these commands through WinRM, you may need to specify the full path to the python executable. For example on your destination PC:
choco install python3
C:\python39\python -m pip install --upgrade pip
[string[]]$Packages = Get-Content -Path "C:\python39\requirements.txt"
$Packages | %{C:\python39\python -m pip install $_.split('==')[0]}
Further Reading
How to upgrade all python packages with pip
https://stackoverflow.com/questions/2720014/how-to-upgrade-all-python-packages-with-pip
Chocolatey
https://chocolatey.org/
Python
https://www.python.org/