StudentHack VI Repository
I still don't know exactly how virtualenv
works but if we use Python for our project it should have it own virtual environment because we'll run it on different machines and we want to stay away from version hell.
With this, every binary is installed in env/bin/
, when you activate
it all the python packages you run will be the ones from env/bin/
and we can keep versions in check.
All you have to do is:
- Install it globally:
pip install virtualenv
- Set it up:
virtualenv --no-site-packages --distribute env
- Activate it (Your shell will say
env)
):source env/bin/activate
(env\Scripts\activate
on Windows) - Install the dependencies:
pip install -r requirements.txt
- When you want to go back to using your global python and pip instances, just type:
deactivate
Another nice thing we can do is:
- Add the following line to every executable:
# env/bin/python3
- Add permissions to the file:
chmod +x script.py
- Run it like this:
./script.py
To run a flask app, all you have to do is:
- Set it up:
export FLASK_APP=app.py
- [Optional]:
export FLASK_DEBUG=1
- Run it with Flask:
flask run
Also if you turn on debugging (export FLASK_DEBUG=1
) before running, the server will reload itself on code changes.
Also when shit goes down the fan, Flask will even show you a console in the browser to help you debug stuff.