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.
I might be missing something crucial, otherwise (almost) every statement / assumption in the question seems incorrect:
It is possible to install / upgrade [GitHub]: mhammond/pywin32 - Python for Windows (pywin32) Extensions using PIP
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
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]> :: 1. Locations [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]> :: 2. PIP test [prompt]> pip list 2>nul | findstr pywin32 [prompt]> :: 3. Download [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]> :: 4. Install [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]> :: 5. PIP test [prompt]> pip list 2>nul | findstr pywin32 pywin32 (222) [prompt]> :: 6. PyWin32 test [prompt]> python -c "import win32api as wapi;print(wapi.GetFileVersionInfo(wapi.__file__, \"\\\\\")[\"FileVersionLS\"] >> 16)" 222 [prompt]> :: 7. Upgrade [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]> :: 8. PIP test [prompt]> pip list 2>nul | findstr pywin32 pywin32 (223) [prompt]> :: 9. PyWin32 test [prompt]> python -c "import win32api as wapi;print(wapi.GetFileVersionInfo(wapi.__file__, \"\\\\\")[\"FileVersionLS\"] >> 16)" 223
Check:
[SO]: How to install a package for a specific Python version on Windows 10? (@CristiFati's answer) - for more details using PIP
[SO]: ImportError: No module named win32com.client (@CristiFati's answer) - for PyWin32 details