如何使用 python 2.7 64 位在 virtualenv 中安装 pywin32?

2024-03-04

我想知道使用 64 位 python 2.7 pywin32 模块在 virtualenv 上安装的正确方法(操作系统是 Windows 7 64 位)。
我找到了 exe 安装程序来源锻造 http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win-amd64-py2.7.exe.

当我首先在命令行上运行 easy_installer 时,一切正常,但很快我就看到了奇怪的行为:当 pywin32-216.win-amd64-py2.7 安装时,它运行 pywin32-216-py2.7-win32.egg 并且失败并出现错误:

No local packages or download links found for pywin32==216
Best match: None

这是我的完整日志:

(sandbox_virtenv) D:\test\py2exe_test>easy_install http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win-amd64-py2.7.exe
Downloading http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win-amd64-py2.7.exe
Processing pywin32-216.win-amd64-py2.7.exe
pywintypes: module references __file__
win32evtlogutil: module references __file__
win32serviceutil: module references __file__
win32timezone: module references __file__
Demos.win32rcparser_demo: module references __file__
Demos.security.sspi.validate_password: module references __file__
isapi.install: module references __file__
isapi.samples.advanced: module references __file__
isapi.samples.test: module references __file__
isapi.test.setup: module references __file__
pywin.framework.scriptutils: module references __file__
pywin.framework.startup: module references __path__
pywin.scintilla.config: module references __path__
pywin.scintilla.control: module references __file__
pywin.scintilla.IDLEenvironment: module references __file__
scripts.regsetup: module references __file__
scripts.setup_d: module references __file__
test.testall: module references __file__
test.test_clipboard: module references __file__
test.test_win32api: module references __file__
test.test_win32rcparser: module references __file__
D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\bdist_egg.py:422: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  symbols = dict.fromkeys(iter_symbols(code))
test.test_win32trace: module references __file__
win32com.__init__: module references __path__
win32com.server.register: module references __file__
win32com.server.register: module references __path__
win32com.test.GenTestScripts: module references __path__
win32com.test.pippo_server: module references __file__
win32com.test.testall: module references __file__
win32com.test.testAXScript: module references __path__
win32com.test.testDictionary: module references __file__
win32com.test.testPippo: module references __file__
win32com.test.testPyComTest: module references __file__
win32com.test.testServers: module references __file__
win32com.test.util: module references __file__
win32comext.adsi.__init__: module references __path__
win32comext.authorization.__init__: module references __path__
win32comext.axcontrol.__init__: module references __path__
win32comext.axdebug.codecontainer: module references __file__
win32comext.axdebug.debugger: module references __file__
win32comext.axdebug.__init__: module references __path__
win32comext.axscript.__init__: module references __path__
win32comext.bits.__init__: module references __path__
win32comext.directsound.__init__: module references __path__
win32comext.directsound.test.ds_test: module references __file__
win32comext.internet.__init__: module references __path__
win32comext.mapi.__init__: module references __path__
win32comext.shell.__init__: module references __path__
win32comext.shell.demos.servers.empty_volume_cache: module references __file__
win32comext.shell.demos.servers.folder_view: module references __file__
win32comext.taskscheduler.__init__: module references __path__
creating 'c:\users\antp~1.kyi\appdata\local\temp\easy_install-kclmxk\pywin32-216-py2.7-win32.egg' and adding 'c:\users\antp~1.kyi\appdata\local\temp\easy_install-kclmxk\pywin32-216-py2.7-win32.egg.tmp' to it
creating d:\test\sandbox_virtenv\lib\site-packages\pywin32-216-py2.7-win32.egg
Extracting pywin32-216-py2.7-win32.egg to d:\test\sandbox_virtenv\lib\site-packages
Adding pywin32 216 to easy-install.pth file
Installing pywin32_postinstall.py script to D:\test\sandbox_virtenv\Scripts
Installing pywin32_postinstall.pyc script to D:\test\sandbox_virtenv\Scripts
Installing pywin32_testall.py script to D:\test\sandbox_virtenv\Scripts
Installing pywin32_testall.pyc script to D:\test\sandbox_virtenv\Scripts

Installed d:\test\sandbox_virtenv\lib\site-packages\pywin32-216-py2.7-win32.egg
Processing dependencies for pywin32==216
Searching for pywin32==216
Reading http://pypi.python.org/simple/pywin32/
Reading http://sf.net/projects/pywin32
Reading https://sourceforge.net/projects/pywin32/files/pywin32/
Reading http://sourceforge.net/project/showfiles.php?group_id=78018
No local packages or download links found for pywin32==216
Best match: None
Traceback (most recent call last):
  File "D:\test\sandbox_virtenv\Scripts\easy_install-script.py", line 8, in <module>
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1712, in main
    with_ei_usage(lambda:
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1700, in with_ei_usage
    return f()
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1716, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "c:\Python27\Lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "c:\Python27\Lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "c:\Python27\Lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 422, in easy_install
    return self.install_item(None, download, tmpdir, deps, True)
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 478, in install_item
    self.process_distribution(spec, dist, deps)
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 519, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 563, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 799, in best_match
    return self.obtain(req, installer) # try and download/install
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 811, in obtain
    return installer(requirement)
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 434, in easy_install
    self.local_index
  File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\package_index.py", line 475, in fetch_distribution
    return dist.clone(location=self.download(dist.location, tmpdir))
AttributeError: 'NoneType' object has no attribute 'clone'

(sandbox_virtenv) D:\test\py2exe_test>

现在我可以从 python win32api 导入,这很令人困惑

(sandbox_virtenv) D:\test\py2exe_test>python
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>>

如果您发现这里有不清楚的地方问我。感谢您的建议。


我明白了这一点,但过程并不愉快。

PyWin32安装程序存在3个问题:

  1. 它从注册表中读取你的 python 安装位置。
  2. 假设您的 lib 目录是包含 python.exe 的目录的子目录
  3. 它将 3 个 dll 转储到 %WINDIR%\system32

因此,如果您在 64 位 Windows 上运行 64 位 python 2.7 或在 32 位 Windows 上运行 32,并且您的虚拟环境位于 c:\scratch\env1\ 中,则过程如下所示:

  1. 将 python.exe 和 pythonw.exe 从 c:\scratch\env1\scripts 复制到 c:\scratch\env1
  2. 将注册表项 HKLM\SOFTWARE\Python\PythonCore\2.7\InstallPath\ 中的值“(默认)”更新为“c:\scratch\env1\”(确保记录旧值。)
  3. 从已激活虚拟环境的命令行中,直接运行 installer.exe 来安装 PyWin32。不要使用 easy_install。
  4. 将 InstallPath 注册表项设置回原始值
  5. 从 c:\scratch\env1\ 中删除 python.exe 和 pythonw.exe
  6. 将 pythoncom27.dll、pywintypes27.dll 和 pythoncomloader27.dll 从 %WINDIR%\system32\ 移动到 c:\scratch\env1\ (不要移动 python27.dll 否则你会后悔的)

这足以在虚拟环境中运行 django-mssql,而无需在虚拟环境之外安装 pywin32。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 python 2.7 64 位在 virtualenv 中安装 pywin32? 的相关文章

随机推荐

  • 释放 Javascript 对象使用的内存

    我应该自己释放分配的内存 还是有一种垃圾收集器 在 JavaScript 中使用以下代码可以吗 function fillArray var c new Array c push 3 c push 2 return c var arr fi
  • 将 Google Analytics 代码放置在 WordPress 特定页面中

    在客户填写联系表单后 我试图让 Google Analytics 代码在感谢页面上工作 并且我尝试使用 HTML 将其放入 Wordpress 后端管理下的页面中的感谢页面中tab 但它似乎在代码之间生成不必要的 p 和 br 标签 特别是
  • 忽略标志指针 0x10ef76ec0 的 RegisterValidateFunction():在 Xcode 中的该地址处找不到标志

    我该如何解决这个问题 W0721 13 54 19 105928 1 commandlineflags cc 1503 忽略标志指针 0x10ef76ec0 的 RegisterValidateFunction 在该地址找不到标志 出现此问
  • Mac OS Gatekeeper 阻止签名命令行工具

    我在 Xcode 中有一个 命令行工具 目标 不是应用程序包 它被 Gatekeeper 阻止 我多年来一直使用这个工具作为我的 PostCheck 地址簿插件的简单安装程序 2012 年 我用我的 Apple 开发者 ID 签署了该工具
  • 如何在android中测量环境温度

    我想在 Android 设备上测量环境温度 但我的设备不包括温度计传感器 我怎样才能测量它 谢谢 这是如何获取的基本示例Android 中的环境温度 import android support v7 app AppCompatActivi
  • Jaspic ServerAuthModule 委托给 JAAS Krb5LoginModule

    我必须编写一个自定义 Jaspic ServerAuthModule 它需要将专有的身份验证 Cookie 添加到 HTTP 响应和 HTTP 请求 以传播到应用程序服务器上运行的应用程序 身份验证必须使用 Kerberos SPNEGO
  • 在Python中将str数据转换为文件对象

    我正在将视频发布到 Google Cloud Buckets 签名的 PUT url 就可以解决问题 但是 如果文件大小大于 10MB 它将无法工作 因此我找到了一个开源项目 可以让我执行此操作 但它使用类似文件的对象 def read i
  • 无法(无法)部署到 Visual Studio Android 模拟器 (Xamarin.Forms)

    调试 Xamarin PCL 项目时遇到问题 我知道代码没问题 因为我可以在 Windows Phone 模拟器上调试它 但无法在 Android 模拟器上调试它 在Win10上使用VS2015 Prof 我可以毫无问题地构建解决方案 只需
  • Ruby on Rails - 创建用户时创建配置文件

    所以基本上我已经编写了自己的身份验证而不是使用 gem 因此我可以访问控制器 我的用户创建工作正常 但是当创建我的用户时 我还想在我的个人资料模型中为他们创建个人资料记录 我已经让它大部分工作了 我只是似乎无法将新用户的 ID 传递到新的
  • erlang 中的错误报告被截断

    警告 erlang n00b 前面 我正在尝试掌握 erlang 并且只是尝试使用牛仔编写一个基本的 hello world 应用程序 我正在模拟一个错误 基本上在代码中的某个位置返回一个无效值 并尝试解释该错误 即 ERROR REPOR
  • 取消引用中的 de- 前缀是什么意思?有语言解释吗?

    我了解到 是 value at 运算符 并且 地址运算符 正式名称为取消引用和引用 每当我和某人交谈时 我都会被 取消引用 这个词绊倒 因为它让我想起 引用 这个词 然后我就感到困惑 从我的学习过程中我知道 如果我知道取消引用的 de 前缀
  • 如何在 Ruby 中按特定顺序对数组进行排序?

    我想按照另一个数组中给出的特定顺序对数组进行排序 例如 考虑一个数组 a one two three b two one three 现在我想按 b 的顺序对数组 a 进行排序 即 a each do t It should be in t
  • Laravel save() 方法后无法检索自定义 id 主键

    对于int自动递增id 在save 方法之后 它返回id 但它不会返回由 mysql 触发器完成的自定义增量 id 主键 productData new Product request gt all productData gt save
  • 使用 SQLServer 驱动程序和 Java 1.6.0_29 Driver.getConnection 挂起

    我不知道该在哪里写一些东西 所以决定在这里写 经过很长一段时间调试我的程序后 我发现调用 Driver getConnection string string string 挂起调用线程 为什么 我真的不知道 但我可以发现这种情况发生在 j
  • 从字符串中删除与字母混合的数字[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 假设我有一个字符串 例如 string This string 22 is not yet perfect1234 and 123pr
  • listItem.File.OpenBinary() 不起作用 - SQL Server 上未启用远程 Blob 存储/文件流是罪魁祸首吗?

    我正在将命令行迁移实用程序从 DEV 移至 QA 但遇到了一个奇怪的错误 当然 一切在开发环境下都能完美运行 这是有问题的代码行 byte fileBytes sourceItem File OpenBinary 无法打开文件错误 内部异常
  • Ruby on Rails - flash 变量

    我对 Rails 完全陌生 在学习过程中 我遇到了使用 flash 变量来维护重定向时下一次回发的数据 我的问题是 什么时候应该使用这个 Rails 如何为我维护它 它是否往返于用户并返回 或者是在服务器端维护 如果它是在服务器端维护的 r
  • 如何使指针可哈希?

    在 Rust 中 我想将枚举视为相等 但仍然能够通过指针区分不同的实例 这是一个玩具示例 use self Piece use std collections HashMap derive Eq PartialEq enum Piece R
  • java rmi传递ImageIcon对象

    我正在做一个rmi client server based program这应该是pass Image object through remote object interfaces 客户端从服务器接收图像 以下是我的代码 在客户处 pub
  • 如何使用 python 2.7 64 位在 virtualenv 中安装 pywin32?

    我想知道使用 64 位 python 2 7 pywin32 模块在 virtualenv 上安装的正确方法 操作系统是 Windows 7 64 位 我找到了 exe 安装程序来源锻造 http sourceforge net proje