This template can be copied to create a project that uses docker for its local interpreter, avoiding the need for
endless venv
directories and installing packages to your local dev system.
Use of this repo requires PyCharm Professional because the community version does not support SSH interpreters.
With this template you get full debugging support and PyCharm behaves as if you were using a local venv
interpreter.
-
Go to
./dev/vars.sh
and adjust theLOCAL_DOCKER_SSH_PORT
variable so that this project's ssh port does not conflict with other projects you may have setup previously. -
RUN
./dev/sshd/create-keys.sh
to create the local ssh keys. You should store these in git for all members of the project. -
Run
./dev/d-pyc.sh
to build and start the local docker interpreter. -
Configure pycharm to use this ssh interpreter:
-
Create an SSH configuration in Pycharm.
- Open: Preferences (cmd/ctrl+,) -> Tools -> SSH Configurations
- Add a new SSH Configuration and set the settings:
-
Create an SSH interpreter in Pycharm using the SSH configuration.
-
Open: Preferences (cmd/ctrl+,) -> Project -> Project Interpreter
-
Click the cog icon on the right and press "Add".
-
Select "SSH Interpreter" and configure it to use the existing SSH configuration we just created. Press Next.
-
Change the remote path mapping to
/app
and uncheck automatic uploads. Press Finish.
-
-
The interpreter setup is complete.
-
-
Whenever you need new pip packages:
- Add the package to the
requirements.txt
file at the project root. - Re-run
./dev/d-pyc.sh
and it will rebuild the environment with the new packages.- Alternatively, Pycharm may prompt you to install the package automatically, this is better for usual work flow.
- If you want updated autocomplete, restart Pycharm. (Autocomplete should update on its own if Pycharm installed the package for you.)
- Add the package to the
dev/d-exec.sh
This script is used to execute arbitrary commands inside a separate dev environment container. For example
./dev/d-exec.sh python3 -m main
would execute the script main.py
located at the repo root.
In most cases you would instead use a PyCharm run configuration to run your code inside the main interpreter container.