Saturday, October 30, 2021

[SOLVED] How to install a python package into an Virtual Environment without activating it?

Issue

Is it possible to install a python package into a virtual environment without activating it?
Imagine you just wish to update a virtual environment without activating it and install the package in it.


Solution

You can use python from a virtual environment without activating the environment. For example if a virtual environment was created at /some/path/to/venv use /some/path/to/venv/bin/python — the program notices it's in a virtual environment and acts as if the environment is activated. To install a package run

/some/path/to/venv/bin/python -m pip install -U package_name


Answered By - phd