Ilia Sidorenko
Ilia Sidorenko

Reputation: 2705

Creating a virtualenv with preinstalled packages as in requirements.txt

Creating a virtualenv will create a virtual python environment with preinstalled pip, setuptools and wheels.

Is there a way to specify what packages to pre-install in that virtualenv apart from those 3 default ones? Either with CLI arguments, a file, or environment variables of some sort.

I.e. is there something along the lines of virtualenv venv && venv/bin/pip install -r requirements.txt which can be run in one command?

Upvotes: 55

Views: 106286

Answers (4)

Deepankar Sharma
Deepankar Sharma

Reputation: 11

Try this: virtualenv --system-site-packages venv

Upvotes: 1

André
André

Reputation: 2020

If you are on Windows (powershell) these are the steps you take:

  1. pip install virtualenv to install virtualenv (if not installed already)
  2. virtualenv venv to create your new environment
  3. venv/Scripts/activate to enter the virtual environment
  4. pip install -r requirements.txt to install the requirements in the current virtual environment

Upvotes: 0

Soviut
Soviut

Reputation: 91545

Typically the steps you always takes are:

  • git clone <repo>
  • cd <repo>
  • pip install virtualenv (if you don't already have virtualenv installed)
  • virtualenv venv to create your new environment (called 'venv' here)
  • source venv/bin/activate to enter the virtual environment
  • pip install -r requirements.txt to install the requirements in the current environment

Upvotes: 106

Ilia Sidorenko
Ilia Sidorenko

Reputation: 2705

You can do it with a tool called pipenv now!

https://www.kennethreitz.org/essays/announcing-pipenv

Just run

pipenv install requests

And it will create a virtualenv and install requests in it

Upvotes: 1

Related Questions