cd
into the directory that will house the project- Using the command
python3 -m venv venv/
will create the virtual environment that will house the required dependencies. - Next, "activate" the virtual environment using the command
source venv/bin/activate
- Now when you use
pip install <package>
it will install that package to the virtual environment for use.
- Now when you use
- If you start getting a
unresolved import ____
orunable to import ____
error in your script, you will need to select a different Python interpretor.- There should be multiple options to select from, but the one I've found the most success with is the
"venv/bin/python3.9"
interpreter.
- There should be multiple options to select from, but the one I've found the most success with is the
- If you need to update the version of python:
- Download from the official python website
- Deactivate the current virtual environmnet
- Remove the venv directory from your project
- Create a new venv pointing to
venv/bin/python3
- Run the command
python3 -m venv --upgrade YOUR_VENV_DIRECTORY
Insight was gained from this article.
- Dyanmic URL parameters can be achieved using either an
F-String
or theformat()
method. - Default encoding will be the default encoding of your virtual environment. If one isn't set, unicode will be used. (This is why I specified the encoding when writing to the file.)
- Context managers spin up the needed resources for the operation at hand, and then automatically closes those resources after completion. This is why the
.close()
method isn't required. - Using
with
effectively can help avoid resource leaks and make code easier to read. - Using context managers with file operations is a common use case, but there are other uses that make sense.
- Connecting to a DataBase
- Lock objects in threading
- Custom conext management classes using the
contextlib
from contextlib import contextmanager
This project is currently a work in progress.