Pydockenv
Python virtual environment, but backed by Docker!
Install / Use
/learn @se7entyse7en/PydockenvREADME
pydockenv
Notice: This project is currently in alpha stage
pydockenv is a library that aims to give the same experience of having a virtual environment, but backed by Docker! The idea is to make the usage of Docker completely hidden so that even non-expert Docker users can leverage the advantages provided by using it as the underlying engine.
Installation
To install pydockenv simply run the following:
pip install pydockenv
Why?
I assume that everybody landing here knows the great advantages that virtual environment brings. The reason I've started this project is that Docker provides even better isolation from the underlying system, and brings the advantage of being really portable across different systems.
In my personal experience sometimes it is difficult to replicate the same local virtual environment, and eventually save it and share it with somebody else, especially if the one you want to share the environment with runs, for example, a different operating system.
Using Docker as the engine of the virtual environment makes the environment itself isolated, easily sharable, and also eventually ready-to-be-deployed given that it is still a Docker container.
Quickstart
The installation will provide you with the pydockenv binary that lets you create, save, load an environment, and handle its dependencies.
Let's start by creating an environment!
Let's create the environment!
To create an environment run the following command:
pydockenv create --name=<env name> <project directory>
For example, if you are in the root of a project named awesome-project this could be:
pydockenv create --name=awesome-project .
This will create a Docker container with the latest Python version installed! If you want to create an environment with a specific Python version you only just need to add the --version=<python version> to the previous command:
pydockenv create --name=awesome-project --version=3.6 .
As you may have noticed, to create the environment you have to set a project directory. This means that everything that is not inside the project directory is completely invisible to the environment. For example, you cannot access a Python script that resides outside your project directory. See the details in the Advanced section.
Creating an environment from a *.toml file
Alternatively, you can use a *.toml file describing your environment. This is analogous to having a requirements.txt file. This file describes both the dependencies and the python version to use, for example:
[tool.pydockenv]
name = "awesome-project"
python = "3.7.4"
[tool.pydockenv.dependencies]
requests = ">=2.22.0"
All the version specifiers described in PEP 440 are supported.
Let's say that this is the content of a pydockenv.toml file in the current working directory. You can then create the environment as follows:
pydockenv create --file=pydockenv.toml <project directory>
You can eventually create it with a different name still using the --name flag:
pydockenv create --file=pydockenv.toml --name=another-awesome-project <project directory>
The *.toml file can be automatically created from an already existing environment by running:
pydockenv export --output=pydockenv.toml
Activation and packages installation
Now you can activate your newly created environment!
source pydockenv activate <env name>
You can verify that the environment has been successfully activated by also running
pydockenv status
With pydockenv you can install Python packages simply by using the install command:
pydockenv install <package>
such as:
pydockenv install requests
and that's it! You can list all your environments and all the packages installed in the currently active environment with the following commands respectively:
# list all environments
pydockenv list-environments
# list packages installed in the current environment
pydockenv list-packages
Running the Python shell
To run the Python shell you simply have to run the shell command:
pydockenv shell
and the shell with the correct version of Python will start.
Running a sample application
Running a Python script is very easy as well. Instead of running it as:
python script.py arg1 arg2 ...
you just have to prefix it with pydockenv run as follows:
pydockenv run python script.py arg1 arg2 ...
And that's it! You're now ready to go! For a more complete overview of the commands see the Examples and the Commands reference sections.
Examples
Here are some examples that are available in the examples directory to show more practically how to use pydockenv.
Hello World!
File: examples/hello_world.py.
This first example just shows how different environments work. The script simply prints the Hello World! string followed by the Python version being used. You can run this in different environments and see how the output changes.
- Environment created with Python 3.8:
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv create --name=hello-world --version=3.8 .
INFO[0000] Creating virtual environment... name=hello-world project-dir=. toml-file= version=3.8
ERROR: You must give at least one requirement to install (see "pip help install")
INFO[0017] Virtual environment created! name=hello-world project-dir=. toml-file= version=3.8
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ source pydockenv activate hello-world
INFO[0000] Activating virtual environment... name=hello-world
INFO[0000] Virtual environment activated! name=hello-world
(hello-world) ✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv run python hello_world.py
INFO[0000] Running command... command="[python hello_world.py]" detach=false env-vars="map[]" ports="[]"
Hello World!
Python version: 3.8.3 (default, Jun 9 2020, 17:39:39)
[GCC 8.3.0]
INFO[0000] Command ran! command="[python hello_world.py]" detach=false env-vars="map[]" ports="[]"
- Environment created with Python 3.7.
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv create --name=hello-world --version=3.7 .
INFO[0000] Creating virtual environment... name=hello-world project-dir=. toml-file= version=3.7
ERROR: You must give at least one requirement to install (see "pip help install")
INFO[0013] Virtual environment created! name=hello-world project-dir=. toml-file= version=3.7
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ source pydockenv activate hello-world
INFO[0000] Activating virtual environment... name=hello-world
INFO[0000] Virtual environment activated! name=hello-world
(hello-world) ✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv run python hello_world.py
INFO[0000] Running command... command="[python hello_world.py]" detach=false env-vars="map[]" ports="[]"
Hello World!
Python version: 3.7.7 (default, Jun 9 2020, 17:58:51)
[GCC 8.3.0]
INFO[0000] Command ran!
Requests
File: examples/requests_get.py.
This second example shows how you can install external packages and run Python scripts by passing arguments as you would do normally.
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv create --name=requests --version=3.8 .
INFO[0000] Creating virtual environment... name=requests project-dir=. toml-file= version=3.8
INFO[0001] Virtual environment created! name=requests project-dir=. toml-file= version=3.8
✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ source pydockenv activate requests
INFO[0000] Activating virtual environment... name=requests
INFO[0000] Virtual environment activated! name=requests
(requests) ✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv install requests
INFO[0000] Installing packages... file= packages="[requests]"
Collecting requests
Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 155 kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Downloading urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
|████████████████████████████████| 126 kB 1.2 MB/s
Collecting idna<3,>=2.5
Downloading idna-2.9-py2.py3-none-any.whl (58 kB)
|████████████████████████████████| 58 kB 1.2 MB/s
Collecting chardet<4,>=3.0.2
Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
|████████████████████████████████| 133 kB 1.4 MB/s
Collecting certifi>=2017.4.17
Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
|████████████████████████████████| 156 kB 1.4 MB/s
Installing collected packages: urllib3, idna, chardet, certifi, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.9 requests-2.24.0 urllib3-1.25.9
INFO[0005] Packages installed! file= packages="[requests]"
(requests) ✔ se7entyse7en in ~/Projects/se7entyse7en/pydockenv/examples $ pydockenv run requests_get.py https://github.com
INFO[0000] Running command... command="[requests_get.py https://github.com]" detach=false env-vars="map[]" ports="[]"
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"requests_get.py\": executable file not found in $PATH": unknown
INFO[0000] Command ran! comm
Related Skills
node-connect
339.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
prose
339.3kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
claude-opus-4-5-migration
83.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
