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?
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.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With