kindanon
kindanon

Reputation: 11

Is there a way to have requirements install dependencies into a virtual environment?

I want to distribute a python script with external requirements, but I don't want to clutter up the users machines. Can I my script activate a virtual environment, and install its requirements to said VE.

Additionally, is there a way to have the VE destroy itself once the script in finished executing.

Upvotes: 1

Views: 1224

Answers (1)

Booboo
Booboo

Reputation: 44118

You do not need to explicitly activate the virtual environment. If the virtual environment is located at /path-to-venv, then executing:

/path-to-venv/bin/pip install package

will install package into the virtual environment. Likewise, running the Python interpreter located at /path-to-venv/bin/python will cause packages to be loaded from the virtual environment located at /path-to-venv without the need for an explicit activation.

Upvotes: 1

Related Questions