How to use the same Python virtualenv on both Windows and Linux
Question:
I started using Windows and Linux recently on the same PC – they are installed to two different partitions, and a third partition contains common data and archives. virtualenvs created from Windows are made with folder “Scripts”, and the counterpart in Linux is the folder “bin”.
The problem here is that the files in those folders are not compatible for both OSes. For example, the “activate” contained in bin (created in Linux) don’t run in Windows, and by the other hand, the “activate” in Scripts (created in Windows) cannot be executed on Linux.
Is there a way to use the same virtualenv on both OSes?
Answers:
Short answer, NO. But you can share the venv build scripts.
-
pip freeze
all libraries to a requirements.txt
file.
pip freeze > requirements.txt
-
Create the venv on each OS:
python -m venv env
source env/bin/activate
pip install -r requirements.txt # Install all the libs.
There are several reasons why venvs cannot be shared across OSes:
- Some packages contains C extensions, and the OS’ .dlls are not compatible with each other.
- venvs contain scripts with hardcoded paths. Windows and Linux paths are different.
I started using Windows and Linux recently on the same PC – they are installed to two different partitions, and a third partition contains common data and archives. virtualenvs created from Windows are made with folder “Scripts”, and the counterpart in Linux is the folder “bin”.
The problem here is that the files in those folders are not compatible for both OSes. For example, the “activate” contained in bin (created in Linux) don’t run in Windows, and by the other hand, the “activate” in Scripts (created in Windows) cannot be executed on Linux.
Is there a way to use the same virtualenv on both OSes?
Short answer, NO. But you can share the venv build scripts.
-
pip freeze
all libraries to arequirements.txt
file.pip freeze > requirements.txt
-
Create the venv on each OS:
python -m venv env source env/bin/activate pip install -r requirements.txt # Install all the libs.
There are several reasons why venvs cannot be shared across OSes:
- Some packages contains C extensions, and the OS’ .dlls are not compatible with each other.
- venvs contain scripts with hardcoded paths. Windows and Linux paths are different.