UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Handling python dependencies

    Scheduled Pinned Locked Moved Solved App Development
    9 Posts 2 Posters 901 Views 2 Watching
    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.
      • A Offline
        aarontheissueguy
        last edited by

        Hello everyone, Im currently writing an app that uses some python libraries I installed using pip3, everything works on my pc and I would now like to package it using clickable, but I have no idea how I can add those libraries to my build. Any tipps on how to do that? thanks already.

        A 1 Reply Last reply Reply Quote 1
        • A Offline
          abmyii @aarontheissueguy
          last edited by

          @aarontheissueguy There are a few ways - all include copying the modules into the package. This should be very easy if you are using a virutalenv, because ideally all the packages required are installed in it (and hopefully no others, because that would be a bit of a waste of space).

          The simplest way is to copy all the folders into the main package folder (i.e. in the same folder as the Python files) since Python will automatically look for the modules in that folder, so it should find them. Note that any modules that have binary files that are specific to one arch will fail on the other arches.

          Another method is to use the PYTHONPATH (https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH) environment variable to point to the folder containing the modules. This can also be done in Python by adding the following to the top of your Python files:

          import sys
          sys.path.append('<PATH>')
          

          This will make Python look for the modules in the provided path.

          A 1 Reply Last reply Reply Quote 1
          • A Offline
            aarontheissueguy @abmyii
            last edited by

            @abmyii Thank you for the response. Yes I am working in a virtual environment. I added the lib and bin folder to the CmakeList and added them to path like this in Python:

            import sys
            sys.path.append('../bin')
            sys.path.append('../lib')
            import Agunua
            from io import StringIO
            import io
            

            This still results in an error if I run clickable desktop though

            A 1 Reply Last reply Reply Quote 0
            • A Offline
              abmyii @aarontheissueguy
              last edited by

              @aarontheissueguy Do you have the project hosted online? It's a bit difficult to debug without understanding the structure. If it's not hosted online, running tree should be enough for me to get an idea of the structure.

              A 1 Reply Last reply Reply Quote 1
              • A Offline
                aarontheissueguy @abmyii
                last edited by

                @abmyii I uploaded the code on GH https://github.com/Aarontheissueguy/AGem its a frontend for the python gemini client Agunua.

                A 1 Reply Last reply Reply Quote 0
                • A Offline
                  abmyii @aarontheissueguy
                  last edited by

                  @aarontheissueguy I see. So I think the problem here is that the libs are in the lib/Python3.8 folder as opposed to directly in the lib/ folder. Try either moving them into the lib/ folder or adding lib/Python3.8 to sys.path.

                  A 1 Reply Last reply Reply Quote 1
                  • A Offline
                    aarontheissueguy @abmyii
                    last edited by

                    @abmyii I was able to import properly thanks.

                    A 1 Reply Last reply Reply Quote 1
                    • A Offline
                      abmyii @aarontheissueguy
                      last edited by

                      @aarontheissueguy Great news!

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        aarontheissueguy
                        last edited by

                        Just to explain the solution if someone stumbles across this with the same question:

                        use sys to add "lib/python3.8/site-packages" to path. note that you not need to "../" out of the src directory. The end result looks like this:

                        import sys
                        sys.path.append('lib/python3.8/site-packages')
                        

                        You might need to change the Python version

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post