dmenv: the stupid virtualenv manager

Installation

Download the dmenv installer, then run python installer.py, or python3 installer.py, depending on how your Python interpreter is called. Just make sure it's Python3, not 2.

The script will fetch pre-compiled binaries from GitHub. If you don't like that, use cargo install dm-env to build from the sources.

Setup

First, dmenv needs one config file named dmenv.toml, located in ~/.config on Linux and macOS, and ~/AppData/Local on Windows.

The config must contain a default environment, like this:

[env.default] python = /path/to/python

Then dmenv needs a setup.py file. If you don't have one yet, run dmenv init --name <project name> to generate one. Make sure to read the comments inside and edit it to fit your needs.

Now you are ready to use dmenv!

lock

Here's what dmenv lock does:

install

Now you can add requirements.lock to your git repo, and then anyone can run dmenv install to install all the deps and get exactly the same versions you got when you ran dmenv lock. Hooray reproducible builds!

run

As a convenience, you can use:dmenv run to run any binary from the virtualenv

show

dmenv show will show you the path of the virtualenv. No more, no less.

On Linux, you might use something like source $(dmenv show)/bin/activate to activate the virtualenv in your shell.

upgrade-pip

Tired of pip telling you to upgrade itself? Run dmenv upgrade-pip :)

It's exactly the same as typing dmenv run -- python -m pip install --upgrade pip, but with less keystrokes :P

Using an other python version

To use a different Python version, add a new section in the dmenv.toml config file with the name and the path to the binary, like this:

toml [env.3.8] python = "/path/to/python3.8" Then you can use Python 3.8 with all the dmenv commands by prefixing them with dmenv --env 3.8.

An other virtualenv will be used in .venv/3.8 so that you can keep your default virtualenv in .venv/default.

Cool, no?

Troubleshooting

You may get this error message when using dmenv with old Python: ``` -> running /mnt/data/dmerej/src/dmenv/demo/.venv/3.6/bin/python -m pip freeze --exclude-editable Error pip freeze failed: Usage: /mnt/data/dmerej/src/dmenv/demo/.venv/3.6/bin/python -m pip freeze [options]

no such option: --exclude-editable ```

The clue to the error is located right above:

You are using pip version 9.0.3, however version 18.1 is available.

Run dmenv upgrade-pip and the problem should go away.

(And learn to read the whole output of the commands you run :)

FAQ

Q: How do I add dependencies to build the documentation?
A: Stick them in the dev section.

Q: What if I don't want to install the dev dependencies?
A: Don't use dmenv. Run pip install without [dev] extras. If you insist, maybe a --no-dev option will be added.

Q: How do I upgrade a dependency?
A: Just run dmenv lock again. If something breaks, either fix your code or use more precise version specifiers

Q: How do I depend on a git specific repo/branch?
A: Edit the requirements.lock by hand like this:

foo==0.1 https://gitlab.com/foo/bar@my-branch

Q: But that sucks and it will disappear when I re-run dmenv lock!
A: Yes that sucks. Feel free to: * Open a pull request if you've forked an upstream project * Use a local pipy mirror and a little bit of CI to publish your sources there

Why?

Why Python3 only?

Why not use virtualenv?

But I don't want to maintain a setup.py!

Too bad. Don't use dmenv, then. poetry is cool.

Why Rust?