You already know something about sys
and pathlib
. Now it's time to learn about venv
.
venv
creates virtual environments (which are a more lightweight than a virtual machine, but they're similar in how they isolate their contents from the rest of your system.
This lets us install third-party libraries in a sane way.
If you don't use them, things get cluttered quickly.
Please read/watch the following:
- A bit about
venv
on windows (youtube) - A bit more about
venv
(stackoverflow)
In this challenge, we'll explore ipython
and rich
.
These libraries are not in the standard library, you'll have to install them.
We'll be putting rich
in a venv.
We'll be running ipython
outside of a venv (unless your system python is weird for some reason, then we'll also run ipython in a venv).
- 3 minutes on why ipython is cool (youtube)
ipython
includes an executable component, so once it's installed, you'll be able to run it like:
$ ipython
Or like this:
$ python -m ipython
venv
(which is already installed because it is part of the standard library) also has an excutable component, but unlike ipython
, it doesn't bother add itself to your path, so you have to run it like this:
$ python -m venv
ipython
is one of the very few things that I like to install system-wide (not in a venv).
I use it as a calculator, and as a way to answer questions about python code which has no external dependencies.
If I ever refer to some python code and say:
try it
I probably mean:
type it into an ipython shell and see what happens
Please follow along with the commands in the next section. There I will show how to install, use, and exit ipython. It has many awesome features, most of which we will ignore for now.
If your system-installed python isn't making that easy, go ahead and do it in a venv instead.