Can't find winpdb even though it's there

Issue #3 resolved
FichteFoll
created an issue

Didn't use the plugin in a while but as I wanted to today this happened.

Petty much same setup as with my previous tickets, Windowsx64 ST3061.

http://i.imgur.com/9XyDDBe.png

Any idea what I'm doing wrong?

Comments (15)

  1. FichteFoll reporter

    Re-appeared and does not go away when restarting ST. No idea what is going wrong.

    I did some digging myself with the traceback given. Running in the ST console:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import rpdb2 ; print(rpdb2.__file__)'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'', b'Traceback (most recent call last):\r\n  File "<string>", line 1, in <module>\r\n  File "C:\\Python27\\lib\\site-packages\\rpdb2.py", line 278, in <module>\r\n    import socket\r\n  File "C:\\Python27\\lib\\socket.py", line 47, in <module>\r\n    import _socket\r\nImportError: DLL load failed: %1 ist keine zul\xe4ssige Win32-Anwendung.\r\n')
    

    (translates to: "%1 is not a valid win32 application")

    However, using the windows command line:

    c:\>"C:\Python27\python.exe" -c "import rpdb2 ; print(rpdb2.__file__)"
    C:\Python27\lib\site-packages\rpdb2.pyc
    

    I also tried with shell=True but it didn't make a difference.

    No idea what is going on.

    For now I need to do this manually in the ST console after which it works:

    import sys
    sys.path.append(r"C:\Python27\lib\site-packages")
    import rpdb2
    
  2. Kay-Uwe (Kiwi) Lorenz repo owner

    Hi FichteFoll,

    I had such an Import error in the past, when I mixed x86 and x64 modules in python, e.g. used a python compiled module for x86 with a x64 python executable. Could this be the issue?

    Kind regards, Kiwi

  3. FichteFoll reporter

    My ST is x64, my Python2.7 is x86.

    I have no idea why this should affect subprocess though, I mean it is designed to run a separate process, which should be independent. Maybe it's an internal issue with subprocess or something required for communication.

  4. Kay-Uwe (Kiwi) Lorenz repo owner

    According to your error message:

    File "C:\\Python27\\lib\\socket.py", line 47, in <module>\r\n    import _socket\r\nImportError: DLL load failed: %1 ist keine zul\xe4ssige Win32-Anwendung.
    

    and your latest post, the _socket.pyd, which is tried to be imported here is most probably 64bit.

    Please run following from your sublimetext console:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import sys ; print(sys.path)'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    

    Make sure, there are not portions of ST3 in your path (e.g. the python module zip).

    For explanation of the error you get, look at this post: http://stackoverflow.com/questions/19019720/importerror-dll-load-failed-1-is-not-a-valid-win32-application-but-the-dlls

    Regards, Kiwi

  5. FichteFoll reporter
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import sys ; print(sys.path)'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b"['', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\sphinx-1.1.3-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\docutils-0.10-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\jinja2-2.6-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\pygments-1.6-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\pip-1.3.1-py2.7.egg', 'C:\\\\Windows\\\\system32\\\\python27.zip', 'C:\\\\Python27\\\\DLLs', 'C:\\\\Python27\\\\lib', 'C:\\\\Python27\\\\lib\\\\plat-win', 'C:\\\\Python27\\\\lib\\\\lib-tk', 'C:\\\\Python27', 'C:\\\\Python27\\\\lib\\\\site-packages', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\wx-2.8-msw-unicode']\r\n", b'')
    
  6. Kay-Uwe (Kiwi) Lorenz repo owner

    try following in sublime-console:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import _socket'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    

    it should fail with error you get in first place.

    Then try:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import sys ; sys.path = ['', 'C:\\Python27\\lib\\site-packages\\sphinx-1.1.3-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\docutils-0.10-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\jinja2-2.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pygments-1.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']; import _socket'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    

    I suppose C:\Windows\system32\python27.zip is the culprit, it should not be in the path of a normal python27 installation. It came most probably with some different installation, and I guess it contains x64 modules.

  7. FichteFoll reporter
    >>> import subprocess
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import _socket'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'', b'Traceback (most recent call last):\r\n  File "<string>", line 1, in <module>\r\nImportError: DLL load failed: %1 ist keine zul\xe4ssige Win32-Anwendung.\r\n')
    
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', "import sys ; sys.path = ['', 'C:\\Python27\\lib\\site-packages\\docutils-0.10-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\jinja2-2.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pygments-1.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']; import _socket"], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'', b'Traceback (most recent call last):\r\n  File "<string>", line 1, in <module>\r\nImportError: DLL load failed: %1 ist keine zul\xe4ssige Win32-Anwendung.\r\n')
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', "import sys ; sys.path = ['C:\\Python27\\lib\\site-packages\\docutils-0.10-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\jinja2-2.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pygments-1.6-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\pip-1.3.1-py2.7.egg', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']; import _socket"], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'', b'')
    

    Note that the last call without the emtpy '' entry seems to work.


    I created a file named import_rpdb2.py in my custom Plugin Debugger folder so that it automatically loads the right module:

    path = r"C:\Python27\lib\site-packages"
    
    import sys
    sys.path.append(path)
    import rpdb2
    sys.path.remove(path)
    

    I disabled it for the calls above (renamed to .pyw), but when it gets loaded and I run the tests, this happens (it works):

    >>> import subprocess
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import _socket'], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    <subprocess.Popen object at 0x00000000046371D0>
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import _socket'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'', b'')
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import sys ; print(sys.path)'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b"['', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\sphinx-1.1.3-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\docutils-0.10-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\jinja2-2.6-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\pygments-1.6-py2.7.egg', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\pip-1.3.1-py2.7.egg', 'C:\\\\Windows\\\\system32\\\\python27.zip', 'C:\\\\Python27\\\\DLLs', 'C:\\\\Python27\\\\lib', 'C:\\\\Python27\\\\lib\\\\plat-win', 'C:\\\\Python27\\\\lib\\\\lib-tk', 'C:\\\\Python27', 'C:\\\\Python27\\\\lib\\\\site-packages', 'C:\\\\Python27\\\\lib\\\\site-packages\\\\wx-2.8-msw-unicode']\r\n", b'')
    
    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import rpdb2 ; print(rpdb2.__file__)'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'C:\\Python27\\lib\\site-packages\\rpdb2.pyc\r\n', b'')
    

    I honestly have no idea what is happening.

  8. Kay-Uwe (Kiwi) Lorenz repo owner

    Somehow there is injected the "" into your python path. Since this is in your normal python installation, it can be that this happens by some pth script from your installations, which is rather improbable.

    More probable is that your environment is tweaked, either your system environment or your environment in ST.

    maybe check your environment variables: computer => properties => advanced system settings => Environment Variables => PYTHON_PATH

    it can also be that PYTHON_PATH is set in your ST environment, you can check it with

    >>> import os, pprint
    >>> pprint.pprint(os.environ.copy())
    
  9. FichteFoll reporter

    I don't have PYTHON_PATH set, neither in ST3, nor in my python27 or in my python33 env. However, if I run these separately the '' path is still present in "sys.path", so in either case it has to be something these envs share. I will have to investigate tomorrow as it's getting quite late today and :time:.

  10. FichteFoll reporter

    So, I have this weird '' in my sys.path on both python27 and python33 envs, yet if I try to import rpdb2 from it it works seemlessly: Python27 console

    I thought that '' is supposed to refer to the current working directory, so I searched for _socket* files in my Python27 folder and found two files:

    C:\Python27\DLLs\_socket.pyd
    C:\Python27\libs\_socket.lib
    

    Then I did this in the console:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import os; print os.getcwd()'], stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'C:\\Program Files\\Sublime Text 3 Portable Beta\r\n', b'')
    

    And suddenly I realized: There is a file named c:\Program Files\Sublime Text 3 Portable Beta\_socket.pyd which is getting imported instead of the usual module.

    Result:

    >>> subprocess.Popen([r'C:\Python27\python.exe', '-c', 'import rpdb2; print rpdb2.__file__'], cwd=os.path.dirname(r'C:\Python27\python.exe'), stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
    (b'C:\\Python27\\lib\\site-packages\\rpdb2.pyc\r\n', b'')
    

    Issue solved.


    Here is another thing that I investigated in between the things I discovered, even though it probably isn't of any interest: https://pastebin.com/hgxRj6Vu

  11. Kay-Uwe (Kiwi) Lorenz repo owner

    Hi FichteFoll,

    yes, you most probably mean with your discovery that, ST3 loads - by loading rpdb2 - many modules from python27 environment. Indeed, this is not intended. I fix this by preloading the modules before loading the rpdb2. So watch out for an update.

    Regards, Kiwi

  12. FichteFoll reporter

    No, this is not what I mean. I just ran my local python interpreter from the command line and from ST's console via subprocess and traced the imports to check where the failure might happen and from where the _socket module was loaded so that I could check if it was indeed something with the current working dictionary.

    Turned out it was much easier to find since _socket.pyd was already in ST's application dir which is what I outlined above.

  13. Log in to comment