Beyond its data science uses, Python can also be used to install development tools. This article covers installing those tools in a manner consistent with the Iron Law of Python Management.
pipx enables you to put Python tools with command-line interfaces in isolated environments.
For server installations, you will use one of the server versions of Python to install
You must also provide the
--user flag so that
pipx is only installed for your account.
$ /opt/python/3.9.2/bin/python -m pip install pipx --user $ /opt/python/3.9.2/bin/python -m pipx ensurepath
pyenv global version of Python, install
pipx and then rehash to make pyenv aware of it:
$ python -m pip install pipx $ python -m pipx ensurepath $ pyenv rehash
Black, a Python tool for formatting code, is a good example of a tool you might want to install this way--you may want to format Python code across several Python projects without installing it into each project.
WDAGUtilityAccount@mvp MINGW64 ~/Documents/python-examples (master) $ pipx install black installed package black 20.8b1, Python 3.9.2 These apps are now globally available - black-primer.exe - black.exe - blackd.exe done! ✨ 🌟 ✨
Confirm that it worked:
WDAGUtilityAccount@mvp MINGW64 ~/Documents/python-examples (master) $ black --version black, version 20.8b1
Notebooks are a popular interface for editing Python data science code. Using them correctly with virtual environments can be a bit challenging because:
- installing packages in the notebook context often does not do the right thing by default
- launching Jupyter from a virtual environment makes it more difficult to do exactly the same thing for each project.
The easiest way to use notebooks with virtual environments on server and desktop is to use the Jupyter extension in VS Code.
Conda is a package and environment manager which you can use to follow many of the strategies outlined in this series. However, many data science packages can be installed easily without it.