54

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?

jkp
  • 78,960
  • 28
  • 103
  • 104

5 Answers5

77

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/python-list@python.org/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?

lofidevops
  • 15,528
  • 14
  • 79
  • 119
  • 2
    specifically, download the pywin32 .exe installer, then do `easy_install -Z` on the .exe file. The `-Z` may not be necessary, but I always do it. – Kevin Horn May 04 '11 at 20:33
  • @KevinHorn: No, you're right, -Z isn't necessary, I just tried it. Thanks! – Scott Stafford Apr 21 '12 at 02:42
  • 1
    used easy_install "http://garr.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win-amd64-py2.7.exe" and worked fine inside the virtualenv – tovmeod Feb 13 '14 at 15:34
  • @tovmeod that's a good point, now that Distribute and setuptools have merged it should be magic :) I'll update the answer – lofidevops Feb 14 '14 at 11:49
  • I realize that this is an older post, and I rarely if ever post on to SO.... But, I just have to say thank you @d3vid I have an x64 Win10 setup and I have been unable to install pywin32 because of the stupid registry bug. Thank you thank you thank you. – Aaron Henderson Mar 04 '16 at 13:34
  • I tried the `easy_install DOWNLOADED_FILE.exe` (because sourceforge is a nightmare) method and got `PermissionError: [WinError 5] Access is denied: 'C:\\Users\\User\\AppData\\Local\\Temp\\easy_install-9txh0ypu\\pywin32-220-py3.5-win-amd64.egg.tmp\\mfc140u.dll'` which cascaded into other errors. However, I am now able to `import win32service` and have confirmed that my service is getting installed, started, etc. So... par for the [Windows] course I guess. – Bruno Bronosky Nov 20 '16 at 20:48
13

For Python 2.7 or 3.x use pypiwin32.

pip install pypiwin32

Andrei Damian-Fekete
  • 1,820
  • 21
  • 27
  • This seemed to work as it got me past the error `Could not find a version that satisfies the requirement pywin32 (from versions: )` that you get with a simple `pip install pywin32`. But, now I get `ImportError: DLL load failed: The specified module could not be found.` even though I see `win32` in my `sys.path`. Any ideas? – Bruno Bronosky Nov 20 '16 at 20:32
  • its kind of late answer but why not. pywin32 is very sensitive to your python version. with pip it supposed to do a good job identifying your python version but apparently it does not. This is why you get the DLL error cause the pywin32 installed does not correspond to yout python versio. so what worked for me is to install it from a whl file that i found in https://www.lfd.uci.edu/~gohlke/pythonlibs/ (unofficial site) – Kostas Markakis Jul 15 '21 at 09:18
4

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.

jkp
  • 78,960
  • 28
  • 103
  • 104
  • I'd *love* to take a look at that repo too – airstrike Jul 08 '13 at 20:58
  • Can you at least list the files you included in the repo? – Korijn Jun 12 '14 at 12:59
  • 6
    This is a terrible, anti-community answer and with 33k+ reputation, you should know better. The "accepted" answer is from OP saying, "nevermind, all you people who helped and who came here via Google, I fixed it but am too busy to show you how." I'm not hating, because I've been there. I just got to call it out because I'd hope someone would have the decency to call me out. – Bruno Bronosky Nov 20 '16 at 20:11
0

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 :

cthepenier
  • 305
  • 3
  • 9
0

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.

tr00st
  • 331
  • 4
  • 15