omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Appex and user modules

    Pythonista
    4
    6
    4819
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • skrohmer
      skrohmer last edited by

      Hi,

      I have created a Python file "ftpx.py" containing only one class which I want to use in several programs. I have stored the file in site-packages. A standard program which imports this file using "from ftpx import FTPx" works fine. An extension program quits with "ImportError: No module named ftpx" as soon as I call it using the appex functionality. What could be the reason? How can I import my own functions also in appex programs?

      Stefan

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        Importing modules from site-packages in the app extension works fine for me.

        Do you have both Pythonista 2 and 3 installed? If so, you might be using the wrong app extension - both are just called "Run Pythonista Script", but Pythonista 3's has a little 3 in the icon. To be sure, scroll all the way to the right, tap the three dots icon, and enable both Pythonista extensions and put them next to each other. Then you can easily see the difference.

        1 Reply Last reply Reply Quote 0
        • skrohmer
          skrohmer last edited by

          I had Pythonista 2 installed before I changed to 3, but now I have installed only 3. I have created some test files. This one is the extension:

          try:
          	import test23
          except:
          	print('test23 not found')
          
          try:
          	import test2
          except:
          	print('test2 not found')
          	
          try:
          	import test3
          except:
          	print('test3 not found')
          

          These are test files located in site-packages and so on...

          test23.py

          print('test23 found in site-packages')
          

          test2.py

          print('test2 found in site-packages-2')
          

          test3.py

          print('test3 found in site-packages-3')
          

          When I start the extension from Pythonista I get this result when using Python 2.7:

          test23 found in site-packages
          test2 found in site-packages-2
          test3 not found

          and this one for Python 3.5:

          test23 found in site-packages
          test2 not found
          test3 found in site-packages-3

          Called as extension I get:

          test23 not found
          test2 not found
          test3 not found

          1 Reply Last reply Reply Quote 0
          • skrohmer
            skrohmer last edited by

            Got it! It works only when using Python 3, either by setting the default to 3.5 or using the shebang #!python3 to override the default interpreter which is set to 2.7 in my case.

            Is this a bug or a feature? ;-)

            1 Reply Last reply Reply Quote 0
            • athros
              athros last edited by

              Folks wanted both Python 2 and Python 3 in the same app, so it's a feature.

              1 Reply Last reply Reply Quote 0
              • chibill
                chibill last edited by

                Yes it's a bug an extension should still import following how it normally does.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors