Docker - Even easier setup of Python
Nothing to install, nothing to configure, nothing to create first.
Here is how to use VSCode and Docker to create a ready-to-user Python environment, whatever if you're under Windows, Linux or Mac.
The only prerequisites are: we should have Docker installed on your system, you should have Visual Studio Code and you've installed the Docker for Visual Studio Code addon in VSCode.
If you've these three things, just do this:
- Start Visual Studio Code
- Press CTRL+SHIFT+P to open the Command Palette. ![Opening the Command Palette]
- Select Dev Containers: Add Dev Container Configuration files...
- And follow the wizard:
- Search for Python
- Select the most recent version of Python, right now it's 3.12-bullseye
- No need to install additional features, just press Enter
- Same for optional files; not needed, just press Enter
This done, VSCode will create a file called .devcontainer/devcontainer.json
See bottom right, please click on the Reopen in Container
button.
Depending on the speed of your computer and if things were already downloaded, you'll get this screen:
See the bottom part, a terminal window has been displayed and you've a prompt showing vscode -> /workspaces/python $
.
Click in the terminal and type python --version
:
Now, for the demo, create a new file called main.py
with this line print("Hello from your Python Devcontainer!")
.
Save the file.
Click in the terminal and type python main.py
to execute the script and tadaaaa: