[!TIP] If you would prefer to run your local development in a Docker container, jump to the Docker Setup section
pyenv
): You can install it from https://brew.sh/.pyenv
for Python Version ManagementWe use pyenv
to manage different versions of Python across machines and projects.
Install pyenv
via Homebrew:
brew install pyenv
Add pyenv
to your shell configuration file (.zshrc
or .bash_profile
):
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc # For zsh shell
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Apply the changes by restarting your shell or running:
source ~/.zshrc
Install the version of Python used in this project (e.g., 3.12.0):
pyenv install 3.12.0
Set the Python version for the project locally:
pyenv local 3.12.0
This creates a .python-version
file in your project that automatically uses Python 3.12.0 for this project.
(Optional) Set Python 3.12.0 as the global version if you want it for all projects:
pyenv global 3.12.0
Create a virtual environment named venv
(or choose another name):
python -m venv venv
Activate the virtual environment:
source venv/bin/activate
venv\Scripts\activate
After activation, you should see (venv)
in your terminal prompt.
Install the project’s dependencies from the requirements.txt
file:
pip install -r requirements.txt
Verify the installation: Run the following command to see the installed dependencies:
pip freeze
Check that Python 3.12.0 is being used in this project:
python --version
You should see Python 3.12.0
(or the version you installed).
Run the Flask application (if you'd like to test the setup):
flask run
To ensure consistency across different machines, we will use a generic chatterly_dev
PostgreSQL user for local development.
Access PostgreSQL (if it's installed locally):
psql postgres
Create the chatterly_dev
user with a password:
CREATE USER chatterly_dev WITH PASSWORD 'chatterly_dev_password';
Create the chatterly_db
database:
CREATE DATABASE chatterly_db;
Grant privileges on the database to the chatterly_dev
user:
GRANT ALL PRIVILEGES ON DATABASE chatterly_db TO chatterly_dev;
.env
FileEnsure your .env
file contains the following environment variables for local development:
DB_USER=chatterly_dev
DB_PASSWORD=chatterly_dev_password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=chatterly_db
This setup will allow you to work with PostgreSQL in local development.
Later, we will add a Flask CLI command to automate the database setup using:
flask db-setup
For now, follow the manual steps above.
For those who prefer to run the app using Docker, follow the steps below.
Make sure you have Docker installed. You can download it from Docker's official website.
Build and run the containers:
docker-compose up --build
This will:
Access the app in your browser:
To stop the containers, press CTRL + C
in the terminal where Docker is running.
Alternatively, you can stop the containers with:
docker-compose down
This command will stop and remove the containers.