如何在 virtualenv 中安装 win32com 模块? [英] How to install win32com module in a virtualenv?
问题描述
我在我的 Windows 7 64 位笔记本电脑上安装了 virtualenv
和 pywin32
,它们似乎都可以工作,但不能相互配合.
I have installed both virtualenv
and pywin32
on my Windows 7 64-bit laptop, and each of them seems to work, but not with each other.
更具体地说,如果 virtualenv 处于活动状态,则在 python 交互式 shell 中运行 import win32com.client
会失败,并显示 No module named win32com.client
.但是,如果没有 virtualenv 处于活动状态,则相同的表达式会成功.
More specifically, if a virtualenv is active, then running import win32com.client
in a python interactive shell fails with No module named win32com.client
. The same expression succeeds, however, if no virtualenv is active.
当我尝试使用 pip
安装 pywin32
(这是我在 virtualenv 处于活动状态时通常安装模块的方式)时,出现错误:
When I try to install pywin32
with pip
(which is how I normally install modules when a virtualenv is active), I get the error:
Could not find any downloads that satisfy the requirement pywin32
No distributions at all found for pywin32
...即使 pywin32
是
pip search pywin32
因此,要安装 pywin32
我必须使用从 SourceForge 下载的 *.exe 安装程序进行安装.
Therefore, to install pywin32
at all I had to install it using an *.exe installer downloaded from SourceForge.
有没有办法在 virtualenv 中安装 pywin32
?
Is there any way to install pywin32
within a virtualenv?
推荐答案
UPDATE 2016
PyPI 上现在有一个可以用 pip 安装的 pywin32 版本.它被称为 pypiwin32
,它使用二进制 wheel
格式安装包.
UPDATE 2016
There is now a version of pywin32 on PyPI that can be installed with pip. It is called pypiwin32
, and it installs the package using the binary wheel
format.
https://pypi.python.org/pypi/pypiwin32
pip install pypiwin32
这将适用于 virtualenv 或 tox 等.
That will work in a virtualenv, or with tox, etc.
在这一行下面是我以前的旧答案.这是现在过时的信息.
Below this line is my previous old answer. That is now outdated information.
旧答案 - 过时了.现代版本的 virtualenv 默认为 --no-site-packages.这意味着无法访问全局站点包现在是默认行为.遗憾的是,(截至 2014 年 7 月)您无法将 pywin32 pip install 安装到您的 virtualenv 中.(这里是错误报告)如果您想让 pywin32 在 virtualenv 中运行,请激活 virtualenv 并使用 easy_install 和 pywin32 安装程序 exe 文件.例如easy_install "C:\Path\To\Downloads\pywin32-219.win32-py3.4.exe"
OLD ANSWER - OUTDATED. Modern versions of virtualenv default to --no-site-packages. That means that not having access to global site-packages is now the default behavior. Sadly, (as of July 2014) you can not pip install pywin32 in to your virtualenv. (here's the bug report) If you want to get pywin32 running inside a virtualenv, activate the virtualenv and use easy_install and the pywin32 installer exe file. For example easy_install "C:\Path\To\Downloads\pywin32-219.win32-py3.4.exe"
这篇关于如何在 virtualenv 中安装 win32com 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!