Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipenv global environment

Tags:

python

pipenv

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.

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

like image 982
Jan Weidner Avatar asked Jul 27 '18 08:07

Jan Weidner


People also ask

What is a Pipenv environment?

Pipenv is a tool that provides all necessary means to create a virtual environment for your Python project. It automatically manages project packages through the Pipfile file as you install or uninstall packages. Pipenv also generates the Pipfile.

Does Pipenv create virtual environment?

Basic Usage. This creates the project_folder folder inside ~/Envs . Alternatively, you can make a project, which creates the virtual environment, and also a project directory inside $WORKON_HOME , which is cd -ed into when you workon project_folder .

Is Pipenv still active?

Pipenv was never dead. The author of that article doesn't know what he's talking about. The latest release of pipenv was 25 days ago and there were 8 releases in 2020. He also says he uses pyenv for virtual environment management, but pyenv doesn't even do that.


1 Answers

Installing from Pipenv without a virtual environment

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

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:

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

An alternative: pipsi

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

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

like image 90
Sam Avatar answered Oct 15 '22 05:10

Sam