SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
Expand all | Collapse all

DLL not found when importing Python module

  • 1.  DLL not found when importing Python module

    Posted Tue February 09, 2021 11:24 AM

    I'm trying to get a large Python 2.7 module transferred from V25 to newer versions.

    I installed IBM SPSS Statistics Subscription. In Edit>Options>File Locations I ticked the Python 27 Location.

    To test, I ran this small piece of code:

    BEGIN PROGRAM.

    import wx

    END PROGRAM.

    As a result I get:

    File "<string>", line 2, in <module>

    File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\__init__.py", line 45, in <module>

    from wx._core import *

    File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 4, in <module>

    import _core_

    ImportError: DLL load failed: The specified module could not be found.

    I'm using 64-bit version of Windows Home, SPSS, Python, wxPython.

    When running Python27 from the command line or from IDLE I have no problems importing wx, which suggests it may have to do with SPSS.

    The idea of translating the 16000 lines of Python27 code to Python 38 doesn't sound too appealing...






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: DLL not found when importing Python module

    Posted Tue February 09, 2021 02:17 PM

    First thing to do is to determine where the wx module is installed. It is probably in a location that is added automatically to the Python search path when running internally but needs to be added to that path in external mode.

    You can do that by creating a sitecustomize.py file in the site-packages directory under your Python 2 installation with a line like

    import sys

    sys.path.append(r"that location")

    Note, also, that there is a Python2 to Python 3 conversion extension command - not yet on the Extension Hub. Read about it and how to get it here

    SPSS Statistics - IBM Data Science Community






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: DLL not found when importing Python module

    Posted Wed February 10, 2021 12:16 PM

    Thanks, Jon. Unfortunately your suggestion doesn't help. I also installed Wing, and Wing turned out to be able to import wx.

    I then copied C:\Pthon27 from my working PC to the new PC with Statistics Subscription. Still the same error message. Both my working PC and the new one only have 64-bit apps.

    The same install files for Python and wxPython (that's the program that needs import wx) were used on my working PC and the new PC.

    SPSS on the Statistics Subscription PC does not have problems importing other modules.

    Regards

    Kees

    And, yes, I read about your conversion extension command; it's on my todo list.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 4.  RE: DLL not found when importing Python module

    Posted Tue February 16, 2021 01:57 PM

    It appears to be an issue related to the Python version used, together with the Subscription version of SPSS (maybe also V26 and or V27, I couldn't check that) as it worked OK with V25 and previous versons

    * This works, as opposed to: BEGIN PROGRAM.

    BEGIN PROGRAM Python3.

    import wx

    END PROGRAM.

    Meaning I'll have a serious go with the aforementioned Python 3 conversion extension command.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 5.  RE: DLL not found when importing Python module

    Posted Tue February 16, 2021 02:32 PM

    In Wing, look at Project > Project Properties. That shows the effective Python search path. wx would have to be on/under one of those locations, which you could add to the search path outside of Wing,






    #SPSSStatistics
    #Support
    #SupportMigration


  • 6.  RE: DLL not found when importing Python module

    Posted Wed February 17, 2021 06:27 PM

    Thank you, Jon.

    In Wing, the Environment Page in Project>Properties shows Use default for Python Executable and for Python Path, and Use inherited environment for Environment.

    The SPSS Python2 program is able to find wx, for the error shows that problems occur running ...wx\__init__.py (see the original post above). It's a DLL that can't be found (but can be found using Python3.

    Kees







    #SPSSStatistics
    #Support
    #SupportMigration


  • 7.  RE: DLL not found when importing Python module

    Posted Wed February 17, 2021 08:58 PM

    There seem to be problems with V27 and Python 2. I have questions pending with Dev. I suggest, if you can, that you use Python 3. You might try changing the option in Wing to use a specific Python 2 distribution that you think is what Statistics is using to see if it still works in Wing.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 8.  RE: DLL not found when importing Python module

    Posted Thu February 18, 2021 02:27 PM

    The project I'm working on consists of a syntax file that (within a BEGIN PROGRAM - END PROGRAM block) imports a .pyc-file.


    I've downloaded STATS_CONVERT_PYTHON.spe which flawlessly translated the syntax file.


    Using the conversion program to next translate the .py-file resulted in an error message saying:

    INFO:lib2to3.main:Output in 'C:\\Temp\\M3\\M2' will mirror the input directory 'C:\\Temp\\M2' layout.

    INFO:RefactoringTool:Skipping optional fixer: buffer

    INFO:RefactoringTool:Skipping optional fixer: ws_comma


    And no translation finds place.


    Do you have any suggestions?

    And an additional question: would it be alright for me to begin with translating my .py module by hand and later apply your translanslation module to the then partly translated file? Or would for example the print x that I translanslated to print (x) be in turn be translated by your program to: print ((x))?


    Kind regards

    Kees








    #SPSSStatistics
    #Support
    #SupportMigration


  • 9.  RE: DLL not found when importing Python module

    Posted Thu February 18, 2021 02:46 PM

    The messages you are getting are just informative. They are not errors. The conversionMessages.txt file written to the output directory sometimes has more information.


    By default, files that were not changed by the conversion are not written to the output location. You can specify COPYALL=YES to have unchanged files also written.


    The conversion logic does not change code that is already valid Python 3 code such as print(x), so such statements will not be altered. However, you might be best off doing a file compare of before and after code if you want to see the effect of the conversion. This won't show you places where the meaning of the code has changed but the syntax hasn't. For example, x/y in Python 2 does integer division if x and y are integers, but in Python 3 it is float division. You would need to change the code to x//y if integer division is meant. The converter can't do this because of the dynamic nature of Python.


    Another place where the conversion would be incomplete is the cmp function. This was eliminated in Python3 (I have no idea why), but the converter doesn't change this, perhaps because you could have your own cmp function that overrides the built-in one. In that case, though, the code would raise an exception when a call is made to cmp.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 10.  RE: DLL not found when importing Python module

    Posted Thu February 18, 2021 09:17 PM

    Thanks for your helpful comments about conversion caveats.


    The errors I mentioned are actually the contents of conversionMessages.txt. As expected conversionMessages.txt appears in the folder C://Temp//M3. But an empty M2 folder is created in C://Temp//M3.

    The output from the conversion extension command is:

    File Conversions: C:\Temp\M2\Snex.pya,b,c

     

    Success

    Failure

    Skipped

    py

    ,000

    1,000

    ,000

    sps

    ,000

    ,000

    ,000

    a. Successful conversions should be checked for correctness

    b. Existing files overwrite option: False

    c. Copy unchanged files option: True







    #SPSSStatistics
    #Support
    #SupportMigration


  • 11.  RE: DLL not found when importing Python module

    Posted Thu February 18, 2021 09:49 PM

    That .py failure is usually due to a file with invalid Python syntax, but I have limited experience with conversion failures to date. Can you send me the .py file to look at (jkpeckSupport Member)?






    #SPSSStatistics
    #Support
    #SupportMigration