如何在Windows和Linux上使用相同的Python virtualenv [英] How to use the same Python virtualenv on both Windows and Linux

查看:133
本文介绍了如何在Windows和Linux上使用相同的Python virtualenv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在同一台PC上使用Windows和Linux-它们安装在两个不同的分区中,第三个分区包含公用数据和存档.从Windows创建的virtualenvs是使用文件夹脚本"创建的,而在Linux中,对应的是文件夹"bin".

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".

这里的问题是这些文件夹中的文件不适用于两种操作系统.例如,bin中包含的激活"(在Linux中创建)不能在Windows中运行,另一方面,脚本(在Windows中创建)中的激活"不能在Linux上执行.

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.

是否可以在两个操作系统上使用相同的virtualenv?

Is there a way to use the same virtualenv on both OSes?

推荐答案

简短答案,不.但是您可以共享venv构建脚本.

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

  1. pip freeze将所有库复制到requirements.txt文件.

  1. 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.
    

  • 无法在操作系统之间共享venv的原因有几个:

    There are several reasons why venvs cannot be shared across OSes:

    1. 某些软件包包含C扩展名,并且OS的.dll不相互兼容.
    2. venvs包含具有硬编码路径的脚本. Windows和Linux路径不同.

    这篇关于如何在Windows和Linux上使用相同的Python virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆