4

As I understand, one cannot use pip to install/upgrade pywin32, though pip install -U pypiwin32 is a workaround.

pywin32 is now hosted on GitHub. I know very little of git but know that it works with binary files. Is there a way to programmatically upgrade the pywin32 binary? That is, say pywin32 v221 is installed with Python v.3.6 (64bit), the program should check against the latest (v223) on GitHub and download the pywin32-223.win-amd64-py3.6.exe and install it. So far, I can only think of a web-scraping-like script that compares the installed version with the latest version on the web and act accordingly. I wonder whether there's a simple solution.

Ancora Imparo
  • 331
  • 1
  • 6
  • 20

2 Answers2

3

I might be missing something crucial, otherwise (almost) every statement / assumption in the question seems incorrect:

  1. It is possible to install / upgrade [GitHub]: mhammond/pywin32 - Python for Windows (pywin32) Extensions using PIP

  2. GitHub is used to host the source code (mainly). The assets there are Mark Hammond's Win installers (since PyWin32 was hosted on SourceForge - long before PIP was born), I suppose they are only built for backward compatibility.
    There is a way to (build and) install directly from GitHub (or any other URL): [SO]: pip install from git repo branch

  3. PIP doesn't download the PyWin32 binary, but .whl (wheel) packages from [PyPI]: Links for pywin32

In order to demo all the above, I created a VirtualEnv, and based on that, a series of steps:

  • Python and PIP executables locations / versions

  • PIP test (list PyWin32 version using PIP) - no output (no PyWin32 installed)

  • PyWin32 download and URL display

  • PyWin32 install (an older version to test upgrade later)

  • PIP test

  • PyWin32 test (list PyWin32 version using PyWin32)

  • PyWin32 upgrade

  • PIP test

  • PyWin32 test

Output:

(py36x64_test) e:\Work\Dev\StackOverflow\q049398198> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###

[prompt]> where python pip
c:\Work\Dev\VEnvs\py36x64_test\Scripts\python.exe
c:\Work\Dev\VEnvs\py36x64_test\Scripts\pip.exe

[prompt]> python -c "import sys;print(sys.version)"
3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]

[prompt]> pip -V
pip 9.0.3 from c:\work\dev\venvs\py36x64_test\lib\site-packages (python 3.6)

[prompt]> :: PIP test

[prompt]> pip list 2>nul | findstr pywin32

[prompt]> pip download -vvv pywin32 2>nul | findstr /i download
  Downloading pywin32-223-cp36-cp36m-win_amd64.whl (9.0MB)
  Downloading from URL https://pypi.python.org/packages/9f/9d/f4b2170e8ff5d825cd4398856fee88f6c70c60bce0aa8411ed17c1e1b21f/pywin32-223-cp36-cp36m-win_amd64.whl#md5=2d211288ee000b6ec5d37436bcbe8a43 (from https://pypi.python.org/simple/pywin32/)
Successfully downloaded pywin32

[prompt]> pip install https://pypi.python.org/packages/be/25/0e0c568456b77ce144dd2b8799f915b046ffa1cd922771d214e4be05bca2/pywin32-222-cp36-cp36m-win_amd64.whl#md5=94a9a3782081e14973c5ae448957d530 2>nul
Collecting pywin32==222 from https://pypi.python.org/packages/be/25/0e0c568456b77ce144dd2b8799f915b046ffa1cd922771d214e4be05bca2/pywin32-222-cp36-cp36m-win_amd64.whl#md5=94a9a3782081e14973c5ae448957d530
  Downloading pywin32-222-cp36-cp36m-win_amd64.whl (9.0MB)
    100% |################################| 9.0MB 135kB/s
Installing collected packages: pywin32
Successfully installed pywin32-222

[prompt]> :: PIP test

[prompt]> pip list 2>nul | findstr pywin32
pywin32 (222)

[prompt]> :: PyWin32 test

[prompt]> python -c "import win32api as wapi;print(wapi.GetFileVersionInfo(wapi.__file__, \"\\\\\")[\"FileVersionLS\"] >> 16)"
222

[prompt]> pip install -U pywin32 2>nul
Collecting pywin32
  Using cached pywin32-223-cp36-cp36m-win_amd64.whl
Installing collected packages: pywin32
  Found existing installation: pywin32 222
    Uninstalling pywin32-222:
      Successfully uninstalled pywin32-222

[prompt]> :: PIP test

[prompt]> pip list 2>nul | findstr pywin32
pywin32 (223)

[prompt]> :: PyWin32 test

[prompt]> python -c "import win32api as wapi;print(wapi.GetFileVersionInfo(wapi.__file__, \"\\\\\")[\"FileVersionLS\"] >> 16)"
223

Check:

CristiFati
  • 38,250
  • 9
  • 50
  • 87
  • 1
    Interesting approach, more accurate than my answer. +1 – VonC Mar 26 '18 at 20:55
  • Thank you, @VonC! I remembered that i installed *pywin32* using *pip* but I didn't have the time to test whether upgrade works as well. – CristiFati Mar 26 '18 at 20:59
  • @CristiFati After I upgraded `pip` to 9.0.3, I can do `pip install pywin32` too. I was using an older version which couldn't. – Ancora Imparo Mar 28 '18 at 04:54
  • I was using *9.0.3* (updated the answer). But I've also been able to install *pywin32* using *pip 9.0.1* (*Python 3.5*) - I don't have an older one. Even if your *pip* would have been really old, it doesn't explain it. Were you able to install other packages using the old *pip*? Or could it be that at the time you've tried the *.whl* was not there (published) yet? – CristiFati Mar 28 '18 at 22:11
  • @CristiFati You could be right that the _.whl_ was not there when I did `pip install -U pywin32`. How can I find out? I have lost track of the timestamps of the updates or upgrades earlier. – Ancora Imparo Apr 01 '18 at 00:17
  • Unfortunately, I don't know. The only thing that comes into my mind is contacting the maintainers and asking for that piece of info. But I think that even if v223 wasn't uploaded yet, v222 should have been. – CristiFati Apr 01 '18 at 08:22
1

You could use Chocolatey and its pywin32 package, but it is out of date.

So a scripting solution as one described in this article (for other programs, but with a similar idea) is possible. See also this gist.
If you uncompress the latest Git for Windows anywhere you want, and use a simplified PATH, you will have access to 200+ Linux commands, including awk, head, etc.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Unfortunately, `pywin32` happens to be one of those that do not support releases. That is, `https://api.github.com/mhammond/pywin32/releases/latest` gives "Not Found". Any idea to tackle this issue? – Ancora Imparo Mar 23 '18 at 03:23