1

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.

kindanon
  • 11
  • 2
  • Does this answer your question? [Activate a virtualenv with a Python script](https://stackoverflow.com/questions/6943208/activate-a-virtualenv-with-a-python-script) – nldoty Jan 14 '20 at 16:49
  • https://stackoverflow.com/search?q=%5Bpython%5D+standalone+executable – phd Jan 14 '20 at 18:14

1 Answers1

1

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.

Booboo
  • 38,656
  • 3
  • 37
  • 60