Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packaged wheels/exes are not compatible with Win XP #811

Closed
bitranox opened this issue Apr 28, 2016 · 21 comments
Closed

Packaged wheels/exes are not compatible with Win XP #811

bitranox opened this issue Apr 28, 2016 · 21 comments

Comments

@bitranox
Copy link

can not load psutil 4.1.0 on Windows XP, SP3, Python 3.4.3 :

Microsoft Windows XP [Version 5.1.2600]
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32

import psutil
Traceback (most recent call last):
File "", line 1, in
File "C:\Python34\lib\site-packages\psutil__init__.py", line 124, in
from . import _pswindows as _psplatform
File "C:\Python34\lib\site-packages\psutil_pswindows.py", line 14, in
from . import _psutil_windows as cext
ImportError: DLL load failed: The specified procedure could not be found.

And I can not update that particular machine, because it is a gateway for an ancient database.
Please Help !

@giampaolo
Copy link
Owner

This is likely due to the old pip version you're using. pip install -U pip should fix this issue.

@giampaolo
Copy link
Owner

Also, closing this as a duplicate of #810.

@robodude666
Copy link

@giampaolo This is actually due to the fact that the psutil whls deployed to pypi are built on Windows Vista or newer (or it seems that way).

The setup.py script sets _WIN32_WINNT based on the result of sys.getwindowsversion() which returns the host OS version, not the target OS. Windows XP does not have the GetTickCount64 API, which was added in Vista. This causes the above crash on import psutil.

Currently, the only way to get psutil to work on Windows XP is to install from source. This can be done with pip install psutil --no-binary :all: which will force pip to download the source and run setup.py manually.

However... that requires you to run on Windows XP. If you want to compile on Windows Vista or newer, and be able to run your python application on Windows XP you can't unless you manually modify the setup.py script before installing on your Vista or newer box.

I recommend not having the setup.py file compile based on the host OS, but instead on an extra parameter, like pip install psutil[winxp] or psutil[win32] and have a lookup table of _WIN32_WINNT values values.

-robodude666

@JokerQyou
Copy link

JokerQyou commented Jun 7, 2016

I think @robodude666 is right. pip install psutil is broken on Windows XP, even with the latest pip (which is 8.1.2 currently).

With pip 8.1.2 I installed psutil 4.2.0, and here is the result:
image

@JokerQyou
Copy link

Update

After trying different history version from pypi, psutil==3.4.2 seems to be the last version unaffected by this issue. All versions of psutil can be installed on Windows XP, but newer version will not work.

@robodude666
Copy link

Yup. Windows XP support from whl was broken with psutil==4.0.0 because of bug fix #761.

3.4.2 was the last version that used GetTickCount for all versions of windows.

@aajtodd
Copy link

aajtodd commented Jul 5, 2016

Seeing this as well. I believe @robodude666 is correct. The logic in ab9f29b checks _WIN32_WINNT to see if GetTickCount64 can be used but that only works if the host OS matches the target when building.

@giampaolo giampaolo reopened this Jul 5, 2016
@giampaolo
Copy link
Owner

Sorry for delaying on this one, I've been busy. As a recap:

  • the problem (breakage of compatibility with WinXP) was introduced in Windows: psutil.boot_time() wraps to 0 after 49 days #761
  • because the exe/wheel files are produced with a more recent Windows version (>= Vista) where GetTickCount64 is available, also the resulting exes/wheels are compiled with such an assumption in place, hence Win XP is unable to use those public exe/wheels
  • Win XP is still compatible if psutil is compiled / installed from source, meaning this issue is with the distribution of exe/wheel files only
  • 3.4.2 is the last psutil version where the distributed exe/wheel files were compatible

@giampaolo
Copy link
Owner

So, as for how to fix this issue: my first idea was to not rely on the C pre-processor (#if (_WIN32_WINNT >= 0x0600) as we do now, and instead use a Windows API which returns the Windows version at runtime, like:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724429(v=vs.85).aspx
...but C doesn't work like that. We need something to dynamically load the DLL at runtime so that "GetTickCount64" is defined in the C code as a string, not an actual function.
I believe something like this would help:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx

@giampaolo
Copy link
Owner

giampaolo commented Jul 6, 2016

...and in fact here it is (Python source code comes to the rescue :P):
http://code.metager.de/source/xref/python/stackless/Python/pytime.c#135

giampaolo added a commit that referenced this issue Jul 6, 2016
@giampaolo
Copy link
Owner

giampaolo commented Jul 6, 2016

I submitted a patch in e481df9.
I am also attaching an exe installer which was produced on Windows 10. Can somebody try it and tell me if it can be installed on Windows XP?
psutil-4.3.0.win32-py2.7.zip

@giampaolo giampaolo changed the title Import of psutil errors with "import _psutil_mswindows .. DLL load failed" on Windows XP 32 Bit Packaged wheels/exes are not compatible with Win XP Jul 6, 2016
@aajtodd
Copy link

aajtodd commented Jul 8, 2016

I tried the build it still fails with the same DLL error.

Glancing over the code again, off the top of my head I would guess any use of _WIN32_WINNT at compile time may cause similar behavior (e.g.

#if (_WIN32_WINNT >= 0x0600) // Windows Vista and above
).

@giampaolo
Copy link
Owner

Mmm, you're right. In this case I'm not sure how to apply the same strategy against the .h file. I suppose C won't allow that. That leaves us with one option only: providing exes/wheels specific for Win XP, but I'm not willing to do that: it's too much effort.

@giampaolo
Copy link
Owner

giampaolo commented Nov 8, 2016

I'm not willing to fix this issue for new versions by distributing XP only exes/wheels but I want to provide a more meaningful error message. Something along the lines of "Windows XP is no longer supported; latest version supporting it is 3.4.2"
I would like to do this when psutil is installed via pip, hence at exe/wheel file level, but I'm not sure how (I asked here http://stackoverflow.com/questions/40492799/wheels-return-error-if-windows-xp).
Alternatively we'll have to do this at import time.

@wiggin15
Copy link
Collaborator

wiggin15 commented Mar 9, 2017

FWIW I don't think there's a problem with the #include that is wrapped with the ifdef (

#if (_WIN32_WINNT >= 0x0600) // Windows Vista and above
) since this can't cause linking errors at runtime. Only functions that will be in the import section of the produced DLL can cause the "DLL load failed error", e.g. the use of "GetIfEntry2" (
dwRetVal = GetIfEntry2(pIfRow);
) - which can be bypassed the same way as GetTickCount64.

However, even if the DLL will load correctly after fixing these calls, there could still be invalid memory access (=crashes) on older systems due to incorrect struct sizes in other places where we use extended classes (e.g.

private = cnt.PrivateUsage;
). These places can also be fixed by determining the Window version at runtime, if we want to do all this work.

In any case, the #include is only for compile time so it will not be a problem as long as we avoid using its definitions on XP. Just my two cents.

@giampaolo
Copy link
Owner

Right now the doc states that latest wheel / exe version compatible with Win XP is psutil 3.4.2.
It also states that it is possible to use latest version by compiling, although it's not guaranteed it will be fully working.

@wiggin15
Copy link
Collaborator

wiggin15 commented Mar 9, 2017

I understand, I'm just pointing out that theoretically it is possible to support WinXP in the same distribution - the header issue (pointed out in #811 (comment)) is not a problem.

@raphael-santos
Copy link

raphael-santos commented Aug 8, 2017

Hi @giampaolo, that same error also happens on Windows Server 2003 R2 x64.

However we are using Python 2.7 with psutil 4.4.2. In this case, the exception is:

Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "psutil\__init__.py", line 124, in <module>
    from . import _pswindows as _psplatform
  File "psutil\_pswindows.py", line 15, in <module>
    from . import _psutil_windows as cext
**ImportError: DLL load failed: The specified procedure could not be found.**

We've tried to updage psutil to version 5.2.2. The exception changed:

Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "psutil\__init__.py", line 126, in <module>
    from . import _pswindows as _psplatform
  File "psutil\_pswindows.py", line 30, in <module>
    raise RuntimeError(msg)
**RuntimeError: this Windows version is too old (< Windows Vista); psutil 3.4.2 is the latest version which  supports Windows 2000, XP and 2003 server**

The only way to use psutil on Windows 2003 Server is with version 3.4.2? Is there a workaround using latest versions?

Thanks

@robodude666
Copy link

@raphael-santos See my response above.

You can manually install psutil from source using pip install psutil --no-binary :all: on the target system to compile for the correct Windows version.

@RicardoNoguerales
Copy link

( Using Windows XP )

pip keeps getting uncompatible binary package

Recently updated Spyder with

pip install --upgrade spyder

This upgraded dependencies too, including psutil, got psutil-5.4.3-cp27-none-win32.whl
( binary not compatible with XP )

Spyder crashed silently during load ( no traceback, pythonw ) ... no clue
Later found a log file with the traceback, uninstalled psutil-5.4.3 , installed 3.4.2 , worked.

And today found this page, updated to 5.4.3 source, worked.

I don't have knowledge about pip and Pypi internals, but wonder if there are no means to avoid this behaviour through some package metadata, so that pip is aware it's running in XP and falls back to download binary 3.4.2 or source 5.4.3 ?

@giampaolo
Copy link
Owner

Windows XP is no longer supported. Latest version supporting it should be 3.4.2. You may try compileing 5.3.3 from sources and it may work (but not sure):
http://psutil.readthedocs.io/en/latest/#faqs

nlevitt added a commit to nlevitt/psutil that referenced this issue Apr 9, 2019
* master: (375 commits)
  update psutil
  fix procsmem script which was not printing processes
  try to fix tests on travis
  try to fix tests on travis
  OSX: fix compilation warning
  giampaolo#936: give credits to Max Bélanger
  giampaolo#811: move DLL check logic in _pswindows.py
  winmake: use the right win slashes
  winmake: do not try to install GIT commit hook if this is not a GIT cloned dir
  giampaolo#811: on Win XP let the possibility to install psutil from sources as it still (kind of) works)
  giampaolo#811: add a Q&A section in the doc; tell what Win versions are supported
  giampaolo#811: raise a meaningful error message if on Windows XP
  update doc; bump up version
  giampaolo#939: update MANIFEST to include only src files and not much else
  update HISTORY
  travis: execute mem leaks and flake8 tests only on py 2.7 and 3.5; no need to test all python versions
  bump up version
  update version in doc
  add simple test case for oneshot() ctx manager
  add simple test case for oneshot() ctx manager
  speedup fetch all process test by using oneshot
  giampaolo#799 - oneshot / linux: speedup memory_full_info and memory_maps
  fix flake8
  first pass
  giampaolo#943: better error message in case of version conflict on import.
  update doc
  799 onshot / win: no longer store the handle in python; I am now sure this is slower than using OpenProcess/CloseHandle in C
  update doc
  (win) add memleak test for proc_info()
  move stuff around
  memleak: fix false positive on windows
  giampaolo#933 (win) fix memory leak in WindowsService.description()
  giampaolo#933 (win) fix memory leak in cpu_stats() (missing free())
  refactoring
  giampaolo#799 / win: pass handle also to memory_maps() and username() functions
  fix numbers
  mem leak script: provide better error output in case of failure
  refactor memleak script
  refactor memleak script
  refactor memleak script
  refactor memleak script
  refactor memleak script: get rid of no longer used logic to deal with Process properties
  memleak script refactoring
  doc styling
  giampaolo#799 / win: use oneshot() around num_threads() and num_ctx_switches(); speedup from 1.2x to 1.8x
  refactor windows tests
  win: enable dueal process impl tests
  win / C: refactor memory_info_2 code() and return it along side other proc_info() metrics
  windows c refactor proc_info() code
  update windmake script
  winmake clean: make it an order of magnitude faster; also update Makefile
  update doc
  bench script: add psutil ver
  winmake: more aggressive logic to uninstall psutil
  adjust bench2 script to new perf API
  try to adjust perf
  upgrade perf code
  memory leak script: humanize memory difference in case of failure
  style changes
  fix giampaolo#932 / netbsd: check connections return value and raise exception
  netbsd / connections: refactoring
  netbsd / connections: refactoring
  netbsd / connections: refactoring
  netbsd / connections: refactoring
  netbsd / connections: refactoring
  testing make clean with unittests was a bad idea after all
  make 'make clean' 4x faster!
  add test for make clean
  adjust winmake script
  fix netbsd/openvsd compilation failure
  bsd: fix mem leak
  osx: fix memory leak
  pre-release
  refactoring
  update IDEAS
  add mtu test for osx and bsd
  osx: separate IFFLAGS function
  osx/bsd: separate IFFLAGS function
  linux: separate IFFLAGS function
  share C function to retrieve MTU across all UNIXes
  HISTORY: make anchors more easily referenceable
  fix giampaolo#927: Popen.__del__ may cause maximum recursion depth error.
  fix Popen test which is occasionally failing
  more releases timeline from README to doc
  ignore failing tests on OSX + TRAVIS
  update INSTALL instructions
  update print_announce.py script
  update HISTORY
  HISTORY: provide links to issues on the bug tracker
  update IDEAS
  giampaolo#910: [OSX / BSD] in case of error, psutil.pids() raised RuntimeError instead of the original OSError exception.
  fix unicode tests on windows / py3
  small test refactoring
  fix giampaolo#926: [OSX] Process.environ() on Python 3 can crash interpreter if process environ has an invalid unicode string.
  osx: fix compiler warnings
  refactor unicode tests
  fix unicode test
  giampaolo#783: fix some unicode related test failures on osx
  test refactoring
  test refactroring
  ...
nlevitt added a commit to nlevitt/psutil that referenced this issue Apr 9, 2019
* 'pslisten' of github.com:nlevitt/psutil: (922 commits)
  Update INSTALL.rst
  Pass python_requires argument to setuptools (giampaolo#1208)
  giampaolo#1152: fix doc to mention CLI command necessary to enable disk_io_counters() on win
  pre release
  pre release
  pre release
  pre-release
  fix giampaolo#1201: document that timeout kwarg is expressed in seconds
  Add mount points to disk_partitions() in Windows (giampaolo#775) (giampaolo#1192)
  add test for cpu_affinity
  what a stupid bug! (giampaolo#1190)
  update doc
  pre release
  pre-release; also get rid of PSUTIL_DEBUG doc instructions (it's kinda useless for the user after all)
  Use FutureWarning instead of DeprecationWarning (giampaolo#1188)
  fix test
  refactor environ() test
  Fix OSX pid 0 bug (giampaolo#1187)
  change assert in test
  refactor Process.__repr__
  Faster Process.children(recursive=True) (giampaolo#1186)
  Speedup Process.children()  (giampaolo#1185)
  update doc
  update HISTORY
  fix giampaolo#1179 / linux / cmdline: handle processes erroneously overwriting /proc/pid/cmdline by using spaces instead of null bytes as args separator
  set x bit to test_aix.py
  fix giampaolo#1181: raise AD if task_for_pid() fails with 5 and errno == ENOENT
  fix posix failure
  Arguments for NoSuchProcess and AccessDenied for the C ext (giampaolo#1180)
  fix travis failure https://travis-ci.org/giampaolo/psutil/jobs/306424509
  be smarter in searching python exe
  do not test platf specific modules on wheelhouse
  try to fix travis failure
  fix travis failures
  try to use PYTHON_EXE instead of sys.executable
  giampaolo#1177: give credits to @wiggin15
  OSX: implement sensors_battery (giampaolo#1177)
  improve error msg for old windows systems giampaolo#811
  add debug messages
  do not mention apt-get as method of installation as it's not recommended
  syntax highlight in doc files
  syntax highlight in doc files
  fix doc indentation
  1173 debug mode (giampaolo#1176)
  code style
  update MANIFEST
  giampaolo#1174: use TimeoutExpired in wait_pid()
  sort imports by name
  Move exceptions to separate file (giampaolo#1174)
  appveyor: enable python warnings when running tests
  refactor winmake.py
  use a C global variable to figure out whether we're in testing mode
  fix unicode err
  define a setup() function which is called on import by all C modules
  move PyUnicode compt fun definition up in the file
  rename C func
  re-enable test on appveyor; remove unused C code
  refactor PSUTIL_TESTING C APIs
  inspect PSUTIL_TESTING env var from C again
  giampaolo#1152: (DeviceIOControl), skip disk on ERROR_INVALID_FUNCTION and ERROR_NOT_SUPPORTED
  giampaolo#1152 / win / disk_io_counters(): DeviceIOControl errors were ignored; che return value and retry call on ERROR_INSUFFICIENT_BUFFER
  upgrade dist cmds
  change make cmds
  disable IPv6 tests if IPv6 is not supported
  travis / OSX: run py 3.6 instead of 3.4
  fix giampaolo#1169: (Linux) users() hostname returns username instead
  update README, bump up version
  get rid of PSUTIL_TESTING env var: it must be necessarily set from cmdline, hence 'python -m psutil.tests' won't work out of the box
  try to set PSUTIL_TESTING env var from python before failing
  skip cpu_freq tests if not available (giampaolo#1170)
  update doc
  pre-release
  giampaolo#1053: drop python 3.3 support
  try to fix appveyor failure; also refactor generate_manifest.py
  giampaolo#1167 give CREDITS to @matray
  Including non-unicast packets in packet count calculation (giampaolo#1167)
  fix giampaolo#1166 (doc mistake)
  provide a 'make help' command
  ifconfig.py humanize bytes
  try to limit false positives on appveyor/windows
  reap_children() in a finally block in order to limit false positives
  unicode tests: use different name for test dir
  fix failure on osx/travis
  update Makefile
  fix test
  giampaolo#1164 give CREDITS to @wiggin15
  AIX: implement num_ctx_switches (giampaolo#1164)
  use new PYTHON_EXE
  improve logic to determine python exe location
  add DEVNOTES file; move TODO.aix into _psutil_aix.c
  Fix test_emulate_energy_full_not_avail (giampaolo#1163)
  update README
  try to limit occasional appveyor failure
  Remove trove classifiers for untested and unsupported platforms (giampaolo#1162)
  Fix giampaolo#1154: remove 'threads' method on older AIX (giampaolo#1156)
  give CREDITS to @adpag for giampaolo#1159, giampaolo#1160 and giampaolo#1161
  Fix test asserts due to leftover test subprocesses (giampaolo#1161)
  Fix network tests for newer ifconfig versions. (giampaolo#1160)
  Fix pre-commit hook for python 3.x. (giampaolo#1159)
  revert last commit
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants