Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?

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?

like image 970
jkp Avatar asked Dec 02 '09 02:12

jkp


People also ask

What is pywin32 package?

This is the readme for the Python for Win32 (pywin32) extensions, which provides access to many of the Windows APIs from Python. See CHANGES. txt for recent notable changes. Only Python 3 is supported.

What is Virtualenv package?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip. Unix/macOS.


2 Answers

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?

like image 123
lofidevops Avatar answered Sep 20 '22 19:09

lofidevops


For Python 2.7 or 3.x use pypiwin32.

pip install pypiwin32

like image 23
Andrei Damian-Fekete Avatar answered Sep 22 '22 19:09

Andrei Damian-Fekete