To keep it all inside your .venv
dependencies, add the dependency paths in the .config/settings.json
, as in this example based on VS Code documentation:
{
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": ".venv/bin/pylint",
"python.formatting.autopep8Path": ".venv/bin/autopep8"
}
This way you don't have to rely on local installs and manual tasks. It's all versioned.
Just make sure you declare those dependencies (dev is the correct type) and that you source
the environment (AKA: activate it). This is a Pipfile
example but anything works.
[dev-packages]
autopep8 = "*"
pylint = "*"
In case you're wondering how to use in-project environments I'll add some examples.
Venv/Virtualenv
There's no big deal here, just create it in-project as usual with the one you prefer:
# venv
python3 -m venv .venv
# virtualenv
python3 -m virtualenv .venv
Activation: source .venv/bin/activate
Pipenv
For Pipenv specifically you have three methods of using in-project .venv
:
- Create the
.venv
directory before installing the dependencies (not in docs for some reason).
- Set
WORKON_HOME
environment variable to your .venv directory.
- Set
PIPENV_VENV_IN_PROJECT
to 1 or True.
Activation: pipenv shell
Currently it is not possible to do it in a dedicated config file. Also, if you set these environment variables in a .env
file they will not work, as explained in the same link.
Poetry
You can explicitly configure Poetry to use {project_home}/.venv
by adding a configuration with the --local
option like this:
poetry config virtualenvs.in-project true --local
This will create a poetry.toml
file which you can then keep as part of your code and not having to worry about it anymore.
[virtualenvs]
in-project = true
Activation: poetry shell