It's very confusing for the beginner to understand how python works with the dependencies and there are lots of tools avaialble in the market try to resolve this problem, for example: pyenv, virtualenv, pyenv-virtualenv, virtualenvwrapper, pyenv-virtualenvwrapper, pipenv, you could check the differnece from stackoverflow

python-virtualenv

There are 3 main problems these tools are trying to resolve.

  • how to choose python version for your project
    • normally differnet OS may have different build in python version and it's always avalialbe in your path
    • but for some project , the developer want to choose a different version of python.
  • how to manage python dependencies for your project
    • python is managing it's dependencies globally by default.
    • one project may want to use version 1 of lib A, but other project may want to use version 2 of lib A, if we still manage the dependencies globally, it will get conflict
    • python tools try to create a virtual env for each specific project, so that each project could manage it's own dependencies. lots of tools , like virtualenv, pyenv-virtualenv, virtualenvwrapper, pyenv-virtualenvwrapper they are all trying to resolve this problem, starting from python 3.3 there is a build in module named venv to help developer to create virtual env too. developer could execute command python3 -m venv to do this.
  • how install 3rd party dependencies for your project
    • pip has become the de facto standard python dependency management tool.
    • pip could use requirements.txt to manage it's dependencies but it can be problematic , that's why pipenv was invented

After a long journey with all of these tools , I finally select pyenv and pipenv to manage my python developmenet env.

I could use pyenv to manage different version of python I could use and install any python version I want into my system. To list all available python versions to install, issue command pyenv install -l, it will give me a long list of avaialble python versions

Available versions:
  2.1.3
  2.2.3
  2.3.7
  ...

to setup a python version for given project, just go to project folder and exec command
pyenv local 3.6.8, this will set my project to use python version 3.6.8 by generating a file named .python-version

Next I could use pipenv to setup my virutal env and manage python dependencies.
I have a system env setup as PYENV_VIRTUALENV_INIT=1 in my ${HOME}/.bash_profile so that pipenv will create venvin folder .venv insidee my project so that my project is just self contained. then I could issue command pipenv install grpcio to install grpc support for python. this command will generate 2 files Pipfile and Pipfile.lock, these 2 files are used to manage python dependencies and expected to be managed by version control system like git. pipenv could also generate requirements.txt to integrate with pip by command pipenv lock -r > requirements.txt

After installed all the python dependencies , we could issue command pipenv shell to activate current python env and it will load dependencies from pipenv managed virtual env

activate-pipenv

There is one drawback when you use pipenv, pipenv is trying to analyse the python dependency and there is a concept named locking in pipenv, for now the locking process may be slow for some python dependency