Today I've learned about Python's virtual environment, aka venv. The venv folder seems to be an unique environment used for each independent project. Python isn't very good at dependency management and for every new package you install, they will be stored in the site-packages/ folder at Python base installation directory.
The value in having a virtual environment comes in a number of ways. first it helps avoid system pollution. Many operating systems including the one I'm using use Python for internal tasks, so installing dependencies directly may cause unintended side effects. Virtual environments avoid dependency conflicts, such that various projects depend on different versions of a package, they can each use the version they're built for.
There seems to be more but this is the gist that I was able to gather, and as such I plan on using virtual environments in all my projects moving forward.
To create my virtual environment I ran the following command
python3 -m venv venv
and to activate it I ran this in my project directory:
source ./venv/bin/activate
Just like that I have built a running website, not that it does much. It takes be to a page that just says welcome, as specified in the homePage function. Its just cool to see a site up and running that quickly
from flask import Flask
# create instance of flask app
app = Flask(__name__)
# decorator sets this as root in website
@app.route("/")
def homePage():
# html that is being run on the page
return "welcome"
if __name__ == "__main__":
app.run()
All code can be found in the repository below :)
https://github.com/BenpaiXD/webchat

Top comments (0)