Skip to content

Setting up new project

Setting up a new project

[1] setup project directory

  • If the project is new, create a new directory and create a requirements.txt file.
  • If the project is an existing python project, clone the repo locally: git clone git clone https://github.com/<user_name>/<repo_name>.git

[2] create virtual environment

CD into the project directory and run python3 -m venv <env_name>

Note: - The env_name is typically called venv but you are free to call it whatever you like - Make sure to add the env_name to the .gitignore file - 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>

[3] activate virtual environment

To start a virtual environment, run source <env_name>/bin/activate

[4] install project dependencies inside the virtual environment

Install project dependencies, run python -m pip install -r requirements.txt

[5] stop the server

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