Startin' Out Part 3 | Python Virtual Env
I am going to share why and how to use a Python virtual environment, and how it relates to libraries and packages.
When working on a project, it has it's own specific directories and files.
When you have Python installed, it is generally installed globally. Meaning you can invoke Python while being almost anywhere in your computer.
When working on your project, virtual environments help isolate libraries and packages (dependencies) to your project. Alternatively to installing them globally on your computer. This is important, It keeps things organized and project specific, so that dependencies do not conflict with other projects you might be working on.
Generally, one would create a virtual environment in the root level of their project. The same level that the .git hidden directory lives on.
When the virtual environment is created a venv
directory is created.
This is where all the files necessary for the virtual environment live.
To create a virtual directory run: python -m venv venv
Your directory will now resemble this at a high level:
your-project/
├── .git/
├── venv/
│ ├── bin/ # On Unix/macOS (Scripts/ on Windows)
│ ├── include/
│ ├── lib/ # Lib/ on Windows
│ └── pyvenv.cfg
├── src/
│ └── main.py
I'll break down the command here: Part 4
Then dig into leveraging lirbraries and packages here: Part 5