Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the same Python virtualenv on both Windows and Linux

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?

like image 853
Cristianjs19 Avatar asked Mar 11 '17 09:03

Cristianjs19


People also ask

Can you share virtual environment Python?

Don't share virtual environments between projects One, it's all too likely that one of the projects in question will suddenly have requirements that break the other project. The whole point of virtual environments is to isolate each project from other projects and their quirks.

Should I use VENV or virtualenv?

If you need the additional features that virtualenv provides over venv, then you obviously should use virtualenv. If you're satisfied with your current setup with venv, then there's no reason to choose virtualenv.


Video Answer


1 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.
like image 139
Shuo Avatar answered Oct 13 '22 06:10

Shuo