Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取virtualenv内部安装的所有软件包的pip install命令_Python_Virtualenv - Fatal编程技术网

Python 获取virtualenv内部安装的所有软件包的pip install命令

Python 获取virtualenv内部安装的所有软件包的pip install命令,python,virtualenv,Python,Virtualenv,我在virtualenv中部署了一个Django应用程序。我现在想将这个应用程序移动到另一台服务器上,为此我需要将所有必需的python包安装到新环境中 有没有工具可以创建一个pip install命令来安装virtualenv中所有已安装的软件包 例如,如果我只在virtualenv中安装了Django和Gunicorn,那么运行所需的工具将输出以下内容: pip安装django==1.6.6。gunicorn==19.1.0(包括版本)创建需求: pip freeze > requir

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

有没有工具可以创建一个pip install命令来安装virtualenv中所有已安装的软件包

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

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

创建需求:

pip freeze > requirements.txt
安装它们:

pip install -r requirements.txt

激活虚拟环境

$ source .venv/bin/activate
然后运行
pip freeze

(.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

这将为您提供该
venv

第一个活动虚拟环境中安装的所有软件包

. env/bin/active
获取virtualenv中安装的软件包列表

pip freeze > list.txt
如果要安装软件包,请在另一个环境中

pip install -r list.txt
所以你可以编写一个小脚本来做这些事情

# -*- 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'
#-*-编码:utf-8-*-
导入系统
导入操作系统
filename=“requirements.txt”
def getlist():
系统(“pip冻结>%s”%(文件名))
def install():
系统(“pip安装-r%s”%(文件名))
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
if len(系统argv)