Confusion between Python and Xojo

  1. 2 months ago

    Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    At some days I don't like developing very much. I've got a tiny little Python helper app that fixes screwed up encodings. The code works fine in the PyCharm IDE. It also works fine when executing the built app from terminal. When using the shell in Xojo to execute the app I get

    Fatal Python error: Py_Initialize: unable to load the file system codec
    zipimport.ZipImportError: can't decompress data; zlib not available

    Current thread 0x00007fff72d82000 (most recent call first):
    Abort trap: 6

    Goggle tells me that this is a problem between different Python installations: "Check PYTHONPATH and PYTHONHOME system variable and make sure it doesn't points to Python 2.x"

    The Xojo docs tell me that a Xojo shell is not the normal shell. Can I change PYTHONPATH and PYTHONHOME dynamically for the Xojo shell to reflect the path to the Python in the app?

    The code needs a library that needs Python 3 so that using the Einhugur plugin for the Python code is not possible.

    Head meets desk: the problem looks like a Xojo bug. I was playing around when I noticed that the Python app before copying worked and after copying the app into Xojo it didn't work anymore. On checking the Finder I saw that the app shrank from 20 MB to 13 MB.

  2. Greg O

    Aug 9 Xojo Inc

    You can set them in the same command you launch python.

    PYTHONPATH=/path/goes/here;PYTHONHOME =/path/goes/here;python command
  3. Björn E

    Aug 9 Pre-Release Testers, Xojo Pro Iceland

    There is Einhugur Plugin for Python 3 also. (we have 2 sets, one for Python 2 and one for Python 3)

  4. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    @Greg OLone : thanks, I'll try this.

    @Björn Einhugur: can I use the plugin at the customer without having Python 3 installed? For myself this is no problem. I can't have my users install Python.

  5. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    Now the usual stupid question: which values for path and home do I need? The Frameworks or the Resources folder in my app?

    The value of PYTHONPATH in PyCharm is:
    'PYTHONPATH': '/Users/beatrixwillius/PycharmProjects/ftfy:/Applications/Develop/PyCharm CE.app/Contents/helpers/pydev:/Users/beatrixwillius/Library/Caches/PyCharmCE2018.2/cythonExtensions',

  6. Greg O

    Aug 9 Xojo Inc

    Go to a terminal and type

    which python
  7. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    The result is: /usr/bin/python

    But this is on my computer. I have a built app - with Py2App - that has it's own version of Python so that the users don't have to install Python.

  8. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    There is also no Python command. I have a very simple shell command:

    dim PythonShell as new Shell
    PythonShell.Mode = 0
    PythonShell.Execute(PathToPython.ShellPath + " " + tempFile.ShellPath)
  9. Greg O

    Aug 9 Xojo Inc

    Ok, so then use

    PathToPython.Parent.ShellPath
  10. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    No success:

    PythonShell.Execute("PYTHONPATH='" + PathToPython.Parent.ShellPath + "';PYTHONHOME ='" + PathToPython.Parent.ShellPath + "';" + PathToPython.ShellPath + " " + tempFile.ShellPath)

    bash: PYTHONHOME: command not found
    Fatal Python error: Py_Initialize: unable to load the file system codec
    zipimport.ZipImportError: can't decompress data; zlib not available

    Current thread 0x00007fff72d82000 (most recent call first):
    bash: line 1: 78995 Abort trap: 6 /Users/beatrixwillius/Documents/Development/Mail\ Archiver/code\ current/Mail\ Archiver\ X.debug.app/Contents/Library/Helpers/fix_encoding.app/Contents/MacOS/fix_encoding /private/var/folders/yr/t1mywwrs1s1d0qv8cwv928240000gn/T/TemporaryItems/com.mothsoftware.mailarchiverx\-temp11

    Then I tried without PYTHONHOME:

    PythonShell.Execute("PYTHONPATH='" + PathToPython.Parent.ShellPath + "';" + PathToPython.ShellPath + " " + tempFile.ShellPath)

    Fatal Python error: Py_Initialize: unable to load the file system codec
    zipimport.ZipImportError: can't decompress data; zlib not available

    Current thread 0x00007fff72d82000 (most recent call first):
    bash: line 1: 79609 Abort trap: 6 /Users/beatrixwillius/Documents/Development/Mail\ Archiver/code\ current/Mail\ Archiver\ X.debug.app/Contents/Library/Helpers/fix_encoding.app/Contents/MacOS/fix_encoding /private/var/folders/yr/t1mywwrs1s1d0qv8cwv928240000gn/T/TemporaryItems/com.mothsoftware.mailarchiverx\-temp12

  11. Greg O

    Aug 9 Xojo Inc
    Edited 2 months ago

    Don’t use single quotes.

  12. Björn E

    Aug 9 Pre-Release Testers, Xojo Pro Iceland
    Edited 2 months ago

    @Beatrix W @Greg OLone : thanks, I'll try this.

    @Björn Einhugur: can I use the plugin at the customer without having Python 3 installed? For myself this is no problem. I can't have my users install Python.

    As far as I know then you always need to install Python to run any sort of Python. (Including when running it from Xojo)

    Unless the OS has it installed of course.

  13. Alberto D

    Aug 9 Pre-Release Testers, Xojo Pro

    I see that zlib is not available. Do your app supply zlib? I can't find zlib. Does Python install zlib?

  14. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    @Greg OLone : no change.

    @Björn Eiacute;ksson : that's what Py2App or PyInstaller are for. They make a sort of runtime environment for Python and bundle this into an application.

    @Alberto de Poo: the zlib is not the problem. Executing the same command

    /Users/beatrixwillius/Documents/Development/Mail\ Archiver/Classes/Build\ Automation/fix_encoding.app/Contents/MacOS/fix_encoding /Users/beatrixwillius/Desktop/filemaker.eml

    from Terminal and not from within the Xojo shell works fine.

  15. Alberto D

    Aug 9 Pre-Release Testers, Xojo Pro
    Edited 2 months ago

    The path to zlib could be the problem. The path from Terminal and the path from Xojo shell are different.

    Edit: where is zlib on your system?

  16. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    @Alberto de Poo: the zlib is in the app. The app thinks that Python is somewhere else and can't find the zlib. But I don't know how to point the app to the correct Python version.

  17. Alberto D

    Aug 9 Pre-Release Testers, Xojo Pro

    Ok, so how about executing bash yourapp instead of your app directly?

    Like Kem commented here: https://forum.xojo.com/48796-shell-in-high-sierra-10-13-5/p1#p396129

  18. Björn E

    Aug 9 Pre-Release Testers, Xojo Pro Iceland

    You might be able to put simply the Python directory into your Xojo App. (I have not tried it)

  19. @Björn Eiacute;ksson You might be able to put simply the Python directory into your Xojo App. (I have not tried it)

    You can certainly do that with PyPy .

  20. Beatrix W

    Aug 9 Pre-Release Testers Europe (Germany)

    @Alberto de Poo: that certainly looks perverted but less so than the ideas I was toying with. For instance, I can do a "do shell script" from an AppleScript. But this needs a fixed script. And I read about dockerizing Python (shudder).

    @Steve Wilson and @Björn Eiacute;ksson : I'll keep copying Python into my app in mind.

  21. Newer ›

or Sign Up to reply!