Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 950
Ilia Sidorenko Avatar asked Jan 02 '17 13:01

Ilia Sidorenko


People also ask

Do I need to install packages in virtual environment?

Installing virtualenv venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section. virtualenv is used to manage Python packages for different projects.


2 Answers

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
like image 130
Soviut Avatar answered Oct 11 '22 12:10

Soviut


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

like image 34
Ilia Sidorenko Avatar answered Oct 11 '22 11:10

Ilia Sidorenko