Last week, my SD card died. I have a python virtual environment on a USB SSD that required a lot of work. Ideally, I'd be able to reactivate the environment, but it seems that none of my original packages are recognized as installed.

I realize that the recommendation before moving a virtual environment is to run:

pip freeze > requirements.txt

I can't do that because all I have left is the SSD drive and a clean Raspbian. Is there any way I can salvage this environment without having to reinstall everything? There are several machine learning libraries that will be a pain in the ass to reinstall.


You can do it if the device is the same. The point of a virtual environment is to be able to replicate it everywhere you need it.

Make a script that installs all necessary dependencies from a requirements.txt file and use it.

Use the command bellow to get the list of all python packages installed:

pip freeze > requirements.txt

Then install the dependencies in another virtual environment on another computer using:

pip install -r requirements.txt`

If you want the exact environment, including system packages, on another computer, use Docker. Sources: 01 - 02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.