Given that you already downloaded the file, go to the directory and activate the virtual environment designed for development.
- Activate the virtual development
$ source venv/bin/activate
- Install the Python packages specified in requirements.txt (Please make sure to double-check the version and dependencies)
(venv)$ pip install -r requirements.txt
- Designate the script to run and specifications to run the program
(venv)$ export FLASK_APP=app.py
(venv)$ export FLASK_ENV=development
- Create the tables (e.g., stocks, users) in the SQLite database in your virtual environment.
(venv)$ flask shell
>>> from project import database
>>> database.create_all()
>>> quit()
- Once the above steps are done, run the flask app in the development server
(venv)$ flask run
- Download the file and unzip it.
- Create a directory.
$ mkdir stock-portfolio-management
$ cd stock-portfolio-management
- Check out the Python version installed. Ideally, Python 3.8.x is recommended in this project.
$ python3 --version
Python 3.8.5
- Virtual environments create an isolated configured setting for each project. In Python 3, a built-in module
venv
can be used for creating a virtual environments by running the command below.
$ python3 -m venv venv
This command creates a folder "venv" that includes a Python interpreter and scripts for activating/deactivating the virtual environment.
(You can also learn more about the importance of virtual environments in Python here: https://realpython.com/python-virtual-environments-a-primer/)
- Start your virtual environment by following the command.
$ source venv/bin/activate
(venv) $
Then, you can find (venv) to the left of the prompt which indicates your virtual environment is successfully activated.
Now that your virtual environment is created and activated, let's install the necessary packages for the project using pip.
- First, let's start with Flask.
(venv) $ pip install flask
This command installs the package and dependencies, such as other packages required for Flask.
- Save the requirements for future use by using the commands below.
(venv)$ pip freeze
click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Werkzeug==1.0.1
Once the requirements for the project are returned in terminal, you can save them in txt file.
(venv)$ pip freeze > requirements.txt
Flask offers development servers that comes with the package. In order to use this mode, we need to specify that the target we're interested in is app.py
and specify that the server is in development mode by using the commands below.
(venv) $ export FLASK_APP=app.py
(venv) $ export FLASK_ENV=development
Use the command below and go to http://127.0.0.1:5000/
to check out your Flask app on your local server.
(venv) $ flask run
* Serving Flask app "app.py" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: ***-***-***