pipenv as isolated place for running a program

I'm new to Linux operating system and currently learning using Ubuntu. I came to the part where you build virtual environment. I read that I should use pipenv instead of venv.

My ideal goal of using a virtual environment is creating an isolated place with all my needs to run a program (easily purge after I don't need the program anymore), but what I learned is using pipenv there's a difference between python packages that can be installed using pipenv and other packages like postgreSQL or git that cannot be installed using pipenv.

As far as I know those packages like postgreSQL and git will be installed in the global (system-wide) and the python packages will be installed in the pipenv environment. Since my ideal goal is creating an isolated place with all the packages to run certain programs, is there a way to make this work?


Solution 1:

I think Python's virtual environments (managed either with venv o pipenv) are just designed to isolate one Python environment from another, that is, for instance, make sure that your Python application runs with the exact version of packages it requires, and does not conflict with another application's requirements.

This has nothing to do with non-Python system tools. So, if you want to build your own experiment environment, with your version of git and postgreSQL etc, your best bet is creating a Virtual Machine (VM) or a container. If you are new to both, perhaps the VM is easier to understand and use (it is like having a dedicated PC for experiments).

That said, in Unix systems it is certainly feasible to manage various version of tools (like git) in the same machine. If you are a developer, you might want to install them locally (e.g. under ~/local/tool-version) and create setup shell scripts that add those tools to the PATH, so that shell will find them instead of the system ones.

For instance you could create a file such as my-git.sh

#!/bin/bash

PATH=~/local/git-1.2.3/bin:$PATH
export PATH

Then when you want to use the tool, in your terminal you could type

$ source my-git.sh

and after this the next time you invoke git in your shell, it will use the binary in ~/local/git-1.2.3/bin (provided there is one there) instead of the system one.

However, a setup like this is much more involved, and does not provide compete isolation (e.g. shared libraries are still the one installed in your sytem)

Hope this helps.