简体   繁体   English

从 pyenv-virtualenv 切换到 pipeenv 时保持相同的共享虚拟环境

[英]Keeping the same, shared virtualenvs when switching from pyenv-virtualenv to pipenv

I started looking at pipenv and it seems to be pretty good.我开始看pipenv ,它似乎很不错。 My only concern is, that most of my projects involve numpy , scipy and some other not-so-small libraries.我唯一担心的是,我的大部分项目都涉及numpyscipy和其他一些不太小的库。

The current way manage my projects: I have pyenv and pyenv-virtualenv installed.当前管理我的项目的方式:我安装了pyenvpyenv-virtualenv I have a few (currently 4) specific virtualenvs that each cater to a type of project.我有几个(目前4)具体virtualenvs每个迎合类型的项目。 The projects themselves have .pyenv-version set, I have the autoload virtualenv feature of pyenv enabled.项目本身设置了.pyenv-version ,我启用了pyenv的自动加载 virtualenv 功能。 If I need to share a project, I generate a requirements.txt with pip freeze -l from the virtualenv .如果我需要共享一个项目,我会使用pip freeze -lvirtualenv生成一个requirements.txt

So in my current setup, I have X number of projects and Y, Y << X number of virtualenvs , all amounting to a few GB of harddisk space.因此,在我当前的设置中,我有X个项目和Y, Y << Xvirtualenvs ,总共有几 GB 的硬盘空间。 Note that because of large libraries like numpy each of the virtualenvs are pretty big, around 700-900 MB.请注意,由于像numpy这样的大型库,每个virtualenvs都非常大,大约 700-900 MB。

My question:我的问题:

As far as I understand, pipenv will, by default create a virtualenv for all of my projects, so the harddisk space taken up by my virtualenvs would increase considerably.据我了解, pipenv默认情况下会为我的所有项目创建一个virtualenv ,因此我的virtualenvs占用的硬盘空间会大大增加。 What I'm interested in is:我感兴趣的是:

  • is it possible to share pipenv environments across several projects, that use exactly the same dependencies?是否可以在使用完全相同依赖项的多个项目之间共享pipenv环境? ie multiple pipenv configs that load the same virtualenv ?即加载相同virtualenv多个pipenv配置?
  • if not, is it possible to generate pipenv config files from a virtualenv I set up with pyenv ?如果没有,是否可以从我用pyenv设置的virtualenv生成pipenv配置文件? ie I would not use pipenv to actually run my projects, I would not create any virtualenvs with pipenv , but I would create pipenv config files for sharing the project (in this case, probably along side a requirements.txt as well).即我不会用pipenv实际运行我的项目,我不会创建任何virtualenvspipenv ,但我会创造pipenv配置文件共享项目(在这种情况下,可能沿着侧requirements.txt为好)。

edit : I rewrote most of the question to make it clearer.编辑:我重写了大部分问题以使其更清楚。

pipenv doesn't seem to be a good fit for your specific workflow because it's project-centric rather than environment-centric. pipenv似乎不太适合您的特定工作流程,因为它以项目为中心而不是以环境为中心。 pipenv treats a virtual environment as volatile and reserves the right to alter it freely if circumstances call for it. pipenv将虚拟环境视为易变的,并保留在情况需要时自由更改它的权利。 You can use it but in the case of alterations to your environments, it will be a pain to keep all projects synchronized due to pipenv 's stricter scrunity.您可以使用它,但在更改环境的情况下,由于pipenv更严格的审查,保持所有项目同步将是一件痛苦的事情。

You can explicitly specify a virtual environment for pipenv to use for a project by creating a .venv file in the project root with a path to it (normally, virtualenvs are created in a specific location with autogenerated names that include a hash of the path to the project).可以通过在项目根目录中创建一个带有路径的.venv文件明确指定pipenv用于项目的虚拟环境(通常,virtualenvs 是在特定位置创建的,其自动生成的名称包含路径的哈希值)该项目)。 This seems to be undocumented.这似乎是无证的。

However, pipenv , unlike virtualenv , checks and enforces that the virtual environment has the exact set of modules satisfying conditions in Pipfile and the exact "last tested configuration" specified in a generated Pipfile.lock .但是, pipenvvirtualenv不同,它检查并强制虚拟环境具有满足Pipfile条件的确切模块集以及生成的Pipfile.lock指定的确切“上次测试配置”。

So, if you change any package version in an environment, you'll need to:因此,如果您更改环境中的任何软件包版本,则需要:

  • update all Pipfile.lock s in affected projects (eg copy the changed one).更新受影响项目中的所有Pipfile.lock (例如复制更改的项目)。 With a generated Pipfile , you may get away with deleting them instead.使用生成的Pipfile ,您Pipfile删除它们。
  • update all Pipfile s in affected projects to the new package versions (eg copy the changed one) if there was a change如果有更改,将受影响项目中的所有Pipfile更新为新的包版本(例如复制更改的版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM