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?

Asked By: Cristianjs19

||

Answers:

Short answer, NO. But you can share the venv build scripts.

  1. pip freeze all libraries to a requirements.txt file.

    pip freeze > requirements.txt
    
  2. 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:

  1. Some packages contains C extensions, and the OS’ .dlls are not compatible with each other.
  2. venvs contain scripts with hardcoded paths. Windows and Linux paths are different.
Answered By: Shuo
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.