我可以将Python窗口包安装到virtualenvs中吗?

Virtualenv非常棒:它允许我保留大量不同的Python安装,以便不同项目的依赖不会全部放在一起。

但是,如果我想在Windows上安装打包成.exe安装程序的软件包,我该如何指导它安装到virtualenv中? 例如,我有pycuda-0.94rc.win32-py2.6.exe。 当我运行它时,它会检查注册表,并且只能找到一个要安装的Python26,这是我的virtualenv基于的一个常见问题。

我怎样才能将它安装到virtualenv中?


是的你可以。 所有你需要的是

easy_install binary_installer_built_with_distutils.exe

惊讶吗? 它看起来像使用distutils的Windows二进制安装程序结合.exe与.zip到一个.exe文件。 将扩展名更改为.zip以查看它是一个有效的zip文件。 在阅读我的问题的答案后我发现了这个问题我可以在哪里下载psycopg2 for Windows的二进制文件?

UPDATE

正如Tritium21在他的回答中指出的那样,您应该使用pip而不是easy_install。 Pip无法安装由distutils创建的二进制包,但它可以以新的轮盘格式安装二进制包。 您可以使用wheel软件包将旧格式转换为新格式,您必须先安装wheel软件包。


我知道这是一个相当古老的问题,并且早于我即将谈论的工具,但为了Google的缘故,我认为提及它是个好主意。 easy_install是python包装的黑羊。 没有人愿意承认使用它的新热点周围。 此外,玩注册表技巧时最适合非标准EXE安装程序(某人自己构建安装程序而不是使用distutils,并且正在检查注册表以查找安装路径),现在对于标准EXE安装程序有更好的方法(c) 。

pip install wheel
wheel convert INSTALLER.EXE
pip install NEW_FILE_CREATED_IN_LAST_STEP.whl

最近作为这篇文章介绍的轮子格式是鸡蛋格式的替代品,填补了许多相同的角色。 这种格式也支持pip(一个已经安装在virtualenv中的工具)。

如果由于某种原因pip install WHEELFILE不起作用,请尝试wheel install WHEELFILE


我最终调整了脚本(http://effbot.org/zone/python-register.htm)在注册表中注册Python安装。 我可以选择Python作为注册表中的Python,运行Windows安装程序,然后设置注册表:

# -*- encoding: utf-8 -*-
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# Adapted by Ned Batchelder from a script
# written by Joakim Löw for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm

import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWAREPythonPythoncore%s" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%sLib;%sDLLs" % (
    installpath, installpath, installpath
)

def RegisterPy():
    try:
        reg = OpenKey(HKEY_LOCAL_MACHINE, regpath)
    except EnvironmentError:
        try:
            reg = CreateKey(HKEY_LOCAL_MACHINE, regpath)
        except Exception, e:
            print "*** Unable to register: %s" % e
            return

    SetValue(reg, installkey, REG_SZ, installpath)
    SetValue(reg, pythonkey, REG_SZ, pythonpath)
    CloseKey(reg)
    print "--- Python %s at %s is now registered!" % (version, installpath)

if __name__ == "__main__":
    RegisterPy()

用你想要注册的Python运行这个脚本,它将被输入到注册表中。 请注意,在Windows 7和Vista上,您需要管理员权限。

链接地址: http://www.djcxy.com/p/26295.html

上一篇: Can I install Python windows packages into virtualenvs?

下一篇: install to vcvarsall.bat?