You can use pyenv to work with different versions of python.
To install:
$ brew install pyenv
Pyenv works with shims. To use them, we need to add this to our shell config:
eval "$(pyenv init -)"
Install a version of Python:
$ pyenv install 3.6.0
Use a pyenv version globally:
$ pyenv global 3.6.0
Use a pyenv version locally:
$ pyenv local 3.6.0
This will add a .python-version
file to the local directory. When you enter this directory, pyenv will recognize the version of Python you want to use. If this version is not installed, pyenv will let you know you need to install it.
pyenv-virtualenv will allow you to set the version of Python you want to use for a project, and have a contained set of packages (like having a separate gemset in the Ruby world).
Install:
$ brew install pyenv-virtualenv
Create a new environment:
$ pyenv virtualenv 3.6.0 my-project-3.6.0
List virtual envs:
$ pyenv vitualenvs
Remove a virtual env:
$ pyenv uninstall my-project-3.6.0
Use a virtual env for the current project:
$ pyenv local my-project-3.6.0
Sometimes you want to know where the location of the installed python you are using is:
$ pyenv which python
You can use the pip package manager to install a package:
$ python -m pip install pylint
After installing a pip package, you can create a requirements file that other can use to load the same packages:
$ python -m pip freeze > requirements.txt
Then someone else can load the requirements file:
$ python -m pip install -r requirements.txt