如何将 pywin32 与 virtualenv 一起使用,而不必包含主机环境的站点包文件夹?

发布于 2024-08-13 07:38:45 字数 510 浏览 11 评论 0原文

我正在 Python 2.6 下使用 PyInstaller,由于 MS 的清单造成了混乱,因此仅部分支持该版本现在影响 Python 的废话,因为它现在是 MSVC8 编译的。

问题是清单嵌入支持依赖于 pywin32 扩展才能构建,这是一个痛苦,因为当我创建 virtualenv (在构建环境中有点失败)我找不到安装所需扩展的方法,以便 PyInstaller 可以访问它们。

有没有人找到这个问题的解决方案?

I'm working with PyInstaller under Python 2.6, which is only partially supported due to the mess MS have created with their manifest nonense which now affects Python since it is now MSVC8 compiled.

The problem is that the manifest embedding support relies on the pywin32 extensions in order to build which is a pain because without including the host's site-packages folder when I create the virtualenv (kinda defeats the point in a build environment) I cannot find a way to install the required extensions so they are accessible to PyInstaller.

Has anyone found a solution to this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

月亮是我掰弯的 2024-08-20 07:38:45

我发现 http://old.nabble.com/Windows:- virtualenv-and-pywin32--td27658201.html(现在是死链接),它提供了以下解决方案:

  1. 浏览 http://sourceforge.net/projects/pywin32/files/ 为您想要的 exe 的 URL
  2. 激活您的 virtualenv
  3. 运行 easy_install http://PATH.TO/EXE/DOWNLOAD

这适用于现代版本的 setuptools(大约 2014 年 2 月,由 tovmeod 在评论中报告)。


如果您使用的是旧版本的 setuptools(或将其分发合并回 setuptools),您可能会收到以下错误消息:

错误:c:\users\blah\appdata\local\temp\easy_install-ibkzv7\pywin32-214.win32-py2.6.exe 不是有效的 distutils Windows .exe

在这种情况下:

  1. 自行下载 exe
  2. 激活您的 virtualenv
  3. 运行easy_install DOWNLOADED_FILE.exe

我宁愿尝试“pip install”而不是“easy_install”,但这不起作用,而且可能永远不会起作用(需要引用)。


最后,我在 http:// /www.mail-archive.com/[电子邮件受保护]/msg272040.html 这是:

通过将 pywin32.pth 文件复制到我的 virtualenv 站点包中解决了这个问题
并编辑文件以指向路径。

如果其他选项不适合您,也许这个可以?

I found http://old.nabble.com/Windows:-virtualenv-and-pywin32--td27658201.html (now a dead link) which offered the following solution:

  1. Browse http://sourceforge.net/projects/pywin32/files/ for the URL of the exe you want
  2. Activate your virtualenv
  3. Run easy_install http://PATH.TO/EXE/DOWNLOAD

This works with modern versions of setuptools (circa February 2014, reported by tovmeod in the comments).


If you are using an old version of setuptools (or distribute it merged back into setuptools), you may get this error message:

error: c:\users\blah\appdata\local\temp\easy_install-ibkzv7\pywin32-214.win32-py2.6.exe is not a valid distutils Windows .exe

In which case:

  1. Download the exe yourself
  2. Activate your virtualenv
  3. Run easy_install DOWNLOADED_FILE.exe

I rather hopefully tried "pip install" rather than "easy_install", but this didn't work, and likely never will (citation needed).


Finally, I found but haven't tested a solution at http://www.mail-archive.com/[email protected]/msg272040.html which is:

Solved this by copying the pywin32.pth file into my virtualenv site-packages
and editing the file to point to the path.

If the other options don't work for you, maybe this will?

何以心动 2024-08-20 07:38:45

对于 Python 2.7 或 3.x,请使用 pypiwin32

pip 安装 pypiwin32

For Python 2.7 or 3.x use pypiwin32.

pip install pypiwin32

耶耶耶 2024-08-20 07:38:45

好吧,既然我必须找到前进的道路,我就即兴发挥。我在内部创建了一个 git 存储库,其中包含 pywin32 的 hacked-together 版本,该存储库将使用标准 setup.py 脚本安装在 virtualenv 中。我花了很多功夫才使其正常工作,但我设法加载它,并且依赖的代码现在可以按照我的需要工作。如果人们认为这对社区有益,请发表评论:如果我得到足够的信息,我会尝试在我的 github 帐户上发布一些内容。

OK, well since I had to find a way forward I improvised. I've internally created a git repository with a hacked-together version of pywin32 that will install within a virtualenv using the standard setup.py script. It took a lot of fiddling to make it work right but I managed to get it to load and the dependent code now works as I need it to. If people feel this would be of benefit to the community please post a comment: if I get enough I'll try and put something up on my github account.

梨涡少年 2024-08-20 07:38:45

自之前的答案以来,这可能已经得到了改进,因为我已经在几台机器上的沙箱上成功安装了 pywin32,没有任何特定的“黑客”:

$ virtualenv sandbox
$ sandbox\scripts\activate
(sandbox) $ git clone https://github.com/Travis-Sun/pywin32.git
(sandbox) $ cd pywin32
(sandbox) $ python setup.py install

使用以下环境进行测试:

This may have been improved since previous answer, since I've successfully installed pywin32 on sandbox on several machines without any specific "hacks" :

$ virtualenv sandbox
$ sandbox\scripts\activate
(sandbox) $ git clone https://github.com/Travis-Sun/pywin32.git
(sandbox) $ cd pywin32
(sandbox) $ python setup.py install

Tested with following environment :

星星的轨迹 2024-08-20 07:38:45

编辑:暂时解决这个问题,安装似乎仍然存在一些问题...

我对整个情况感到相当厌倦,只是创建了一组改装的轮子(“轮转换<.exe>”)。我会尽力在最新版本中维护它们,但如果有任何问题,请大声喊叫。

https://tr00st.co.uk/python/wheel/pywin32/

安装即可使用 pip 并指向与您的版本和体系结构匹配的包可以轻松完成。例如,对于 Python 3.5/amd64:

pip install https://tr00st.co.uk/python/wheel/pywin32/pywin32-219-cp35-none-win_amd64.whl

警告:--upgrade 过程当前失败,因为卸载过程无法自行清理(清理 win32api.pyd 时访问被拒绝) - 仅在删除临时目录时有效,可以手动删除临时目录。最简单的方法是卸载并重新安装而不是升级,然后手动删除临时文件夹。

Edit: Scratch this for now, appears to be some problems with the installation still...

I got rather tired of the whole situation, and just created a set of converted wheels ("wheel convert <.exe>"). I'll try and keep them maintained for the most recent build, but do shout if there are any issues.

https://tr00st.co.uk/python/wheel/pywin32/

Installation can be done easily using pip and pointing to the package matching your version and architecture. For example, for Python 3.5/amd64:

pip install https://tr00st.co.uk/python/wheel/pywin32/pywin32-219-cp35-none-win_amd64.whl

Caveat: The --upgrade process currently fails, as the uninstall procedure is unable to clean up after itself (Access Denied when cleaning up win32api.pyd) - this is only when removing the temporary directory, which can be manually deleted. Easiest way around this is to uninstall and reinstall instead of upgrading, then manually delete the temporary folder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文