Pipenv 全局环境 [英] Pipenv global environment

查看:34
本文介绍了Pipenv 全局环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pipenv 是管理 Python 环境的好工具.但有些事情需要全球化.例如,大多数命令行工具应该始终可用,并且 jupyter 应与非 Python 内核一起使用.

Pipenv is a good tool for managing python environments. But some things need to be global. For instance most command line tools should be always available and jupyter for use with non python kernels.

pipenv 也可以用来管理这样的全局 python 环境吗?如果是这样,如何?这是明智的做法吗?

Can pipenv be used to manage such a global python environment as well? If so, how? Is this a sane thing to do?

推荐答案

在没有虚拟环境的情况下从 Pipenv 安装

我遇到了与您类似的问题 - 我需要在我们的生产服务器上全局安装依赖项.

I had a similar problem to you - I needed to install dependencies globally on our production server.

我遇到了这个讨论,它提醒我注意--system 选项.pipenv install --system 全局安装依赖.

I came across this discussion which alerted me to the --system option. pipenv install --system installs dependencies globally.

全局安装仅部分依赖项

Installing only some dependencies globally

我认为我也应该解决您的问题的其他几个方面:

There are a couple of other aspects of your question which I thought I should address too:

首先,您谈到某些"事物是全球性的.如果您有一些需要全局的依赖项和一些需要在虚拟环境中的依赖项,您可以将它们拆分为单独的 Pipfiles 并使用 PIPENV_PIPFILE 环境变量.例如:

First of all, you talk about "some" things being global. If you have some dependencies which need to be global and some which need to be in a virtual environment, you could split them into separate Pipfiles and use the PIPENV_PIPFILE environment variable. For example:

# Install your global deps from a separate file
$ PIPENV_PIPFILE="/path/to/global/deps/Pipfile" pipenv install --system

# Use your local Pipfile for the project-specific deps (in a virtual environment as normal)
$ pipenv install

另一种选择:pipsi

其次,您会问这样做是否明智?"我认为将 Pipenv 用于全局依赖是明智的,但是对于命令行工具的用例,我会使用 pipi.Pipsi 全局安装库,但彼此隔离(有关更多详细信息,请参阅链接).但是,我认为它没有提供使用需求文件的方法(ref).

Secondly, you ask "is this a sane thing to do?" I think is is sane to use Pipenv for global dependencies in general, but for your use case of command-line tools, I would use pipsi. Pipsi installs libraries globally but isolated from each other (see the link for more details). However, I don't think it offers a way of using a requirements file (ref).

对于一些关于 Python 设置和依赖项的一般性阅读,我真的推荐 Jacob Kaplan-Moss 的文章 我的 Python 开发环境,2018 版.

For some general reading about Python setup and dependencies, I really recommend Jacob Kaplan-Moss's article My Python Development Environment, 2018 Edition.

这篇关于Pipenv 全局环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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