获取virtualenv中安装的所有软件包的pip install命令

时间:2021-02-27 21:37:36

I have a Django application deployed in a virtualenv. I want to move this app to another server now, and for that I need to install all required python packages to the new environment.

我在virtualenv中部署了一个Django应用程序。我想将此应用程序移动到另一台服务器,为此我需要将所有必需的python包安装到新环境中。

Is there a tool to create a pip install command to install all the installed packages within a virtualenv?

是否有工具来创建pip install命令以在virtualenv中安装所有已安装的软件包?

For example, if I only installed Django and Gunicorn within a virtualenv, running the desired tool would output the follwing:

例如,如果我只在virtualenv中安装了Django和Gunicorn,运行所需的工具将输出以下内容:

pip install django==1.6.6. gunicorn==19.1.0 (including the versions)

pip install django == 1.6.6。 gunicorn == 19.1.0(包括版本)

3 个解决方案

#1


6  

Create requirements:

创建要求:

pip freeze > requirements.txt

Install them:

安装它们:

pip install -r requirements.txt

#2


1  

Activate virtual environment

激活虚拟环境

$ source .venv/bin/activate

Then run pip freeze

然后运行pip冻结

(.venv)my@ubuntu:~/$ pip freeze
astroid==1.3.4
Babel==1.3
beautifulsoup4==4.3.2
coverage==3.7.1
d2to1==0.2.11
elasticsearch==1.4.0
flake8==2.3.0
netaddr==0.7.13
netifaces==0.10.4
nose==1.3.4
oslo.config==1.6.0
oslo.i18n==1.3.1
oslo.serialization==1.2.0
oslo.utils==1.2.1
pbr==0.10.0
pecan==0.6.1
pep8==1.6.2
pika==0.9.14
prettytable==0.7.2
pyflakes==0.8.1
Pykka==1.2.0
pylint==1.4.1
python-keystoneclient==0.11.2
pytz==2014.10
requests==2.5.0
setuptools-git==1.1
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.9.0
stevedore==1.1.0
urllib3==1.10.2
waitress==0.8.9
WebOb==1.4
WebTest==2.0.9
WSME==0.5b6

This will give you all installed package in that venv.

这将为您提供该venv中所有已安装的软件包。

#3


0  

First active virtual env

第一个活跃的虚拟环境

. env/bin/active

get list of packages installed in virtualenv

获取virtualenv中安装的软件包列表

pip freeze > list.txt

in another environment if you want to install the packages

在另一个环境中,如果要安装软件包

pip install -r list.txt

So you could wirte a little script to do these things

所以你可以用一个小脚本来做这些事情

# -*- coding: utf-8 -*-
import sys
import os
filename = "requirements.txt"

def getlist():
    os.system("pip freeze > %s" %(filename))

def install():
    os.system("pip install -r %s" %(filename))

if __name__ == '__main__':
    if len(sys.argv) <= 1:
        print 'Please choose,list or install'
        exit(0)
    if sys.argv[1] == "list":
        getlist()
    elif sys.argv[1] == "install":
        install()
    else:
        print 'Please input list or install'

#1


6  

Create requirements:

创建要求:

pip freeze > requirements.txt

Install them:

安装它们:

pip install -r requirements.txt

#2


1  

Activate virtual environment

激活虚拟环境

$ source .venv/bin/activate

Then run pip freeze

然后运行pip冻结

(.venv)my@ubuntu:~/$ pip freeze
astroid==1.3.4
Babel==1.3
beautifulsoup4==4.3.2
coverage==3.7.1
d2to1==0.2.11
elasticsearch==1.4.0
flake8==2.3.0
netaddr==0.7.13
netifaces==0.10.4
nose==1.3.4
oslo.config==1.6.0
oslo.i18n==1.3.1
oslo.serialization==1.2.0
oslo.utils==1.2.1
pbr==0.10.0
pecan==0.6.1
pep8==1.6.2
pika==0.9.14
prettytable==0.7.2
pyflakes==0.8.1
Pykka==1.2.0
pylint==1.4.1
python-keystoneclient==0.11.2
pytz==2014.10
requests==2.5.0
setuptools-git==1.1
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.9.0
stevedore==1.1.0
urllib3==1.10.2
waitress==0.8.9
WebOb==1.4
WebTest==2.0.9
WSME==0.5b6

This will give you all installed package in that venv.

这将为您提供该venv中所有已安装的软件包。

#3


0  

First active virtual env

第一个活跃的虚拟环境

. env/bin/active

get list of packages installed in virtualenv

获取virtualenv中安装的软件包列表

pip freeze > list.txt

in another environment if you want to install the packages

在另一个环境中,如果要安装软件包

pip install -r list.txt

So you could wirte a little script to do these things

所以你可以用一个小脚本来做这些事情

# -*- coding: utf-8 -*-
import sys
import os
filename = "requirements.txt"

def getlist():
    os.system("pip freeze > %s" %(filename))

def install():
    os.system("pip install -r %s" %(filename))

if __name__ == '__main__':
    if len(sys.argv) <= 1:
        print 'Please choose,list or install'
        exit(0)
    if sys.argv[1] == "list":
        getlist()
    elif sys.argv[1] == "install":
        install()
    else:
        print 'Please input list or install'