Setting up a new project
Create Virtual Environment
To create a virtual environment, run python3 -m venv <env_name>
Note:
- The
env_nameis typically called.venvin order to make the directory hidden. - Make sure to add the
env_nameto the.gitignorefile. - If the project requires a specific python version, you must install the python version manually, and then you can specify that version by running
python3.x -m venv <env_name>
Activate Virtual Environment
To start a virtual environment, run source <env_name>/bin/activate
Install Project Dependencies Inside the Virtual Environment
To install project dependencies, run pip install -r requirements.txt
Deactivate Virtual Environment
To stop the server, run deactivate
Docker notes
If you intend to run the app inside of docker, create a Dockerfile specifying the python version required. Note that the steps above will still be required in order for the IDE to know about the packages and import them.
Resources
- https://realpython.com/python-virtual-environments-a-primer/
- https://stackoverflow.com/questions/37094032/how-to-run-cloned-django-project
- https://stackoverflow.com/questions/22681824/how-do-i-use-different-python-version-in-venv-from-standard-library-not-virtua