This repository exists because every time I have to set up a new Python project, there is just too much I have to do. So here is a useful template for myself. Feel free to clone it or download it if you want.
The project contains a Makefile
so that useful but long commands can be run without too much thinking. Besides, mypy
, pylint
are also configured.
A .env
file lets you choose the project's name, the Python version and more stuff. Check the file please.
This template is to develop a PyTorch project, but you can change it to whatever you want.
It is implied that you are on Mac/Linux. No Windows.
Make sure you have Python >=3.8.13
(3.10.10
recommended).
Create a virtual environment with any tool you prefer.
Use any tool to create a virtual environment with the indicated Python version.
With Pyenv (recommended, here is the installer), it is very easy to install the Python version you want, create a virtual environment and activate it.
Once Pyenv is installed, run:
pyenv install 3.10.10
pyenv virtualenv 3.10.10 <project-name>
pyenv activate <project-name>
or just:
make init
Once the virtual environment is active, install the present project and all dependencies by running:
pip install --upgrade pip
pip install --upgrade poetry
poetry install --no-cache
Make sure you are calling the correct python
, pip
and poetry
. In case you're not sure, prepend python -m
before all above commands.
Alternatively, you can also just run:
make install
which does all the work for you.
Build project's image as follows:
docker build -t <project-name> -f Dockerfile .
# or alternatively
make build
The present folder will be mounted at /workdir
.
- To start a Bash session in the container, run:
make bash
- To start a Jupyter Notebook (+ a Tensorboard), run:
make up
. Then runmake down
when you're done. - To run PyTest from the container, run:
make pytest-image
- To start a Python session in the container, run:
make docker-python
- To start a development container, run:
make dev-container
ormake up
(if you go for this one, you can then kill the container withmake down
). Make sure that you're notroot
in the container. To see if a user with your local username and userid exists inside the container, runcat /etc/passwd
. Then, you can runsu - <your-username>
to change user insinde the dev container.
Please also note that our image's entrypoint is the script entrypoint.sh. This script solves common permission problems for developers who wish to mount their local source code directory on a container, as explained here. TL;DR: you will be logged into your container as your current user, thus avoinding any permission errors.
Please check the examples
folder: here
Check the experiments
folder: readme
If you wish to contribute to the project, please see here