🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to import my own module into a project?

    General
    4
    9
    13.6k
    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
      Alexander
      last edited by

      Hello. I'm new to m5stack. I have a possibly simple question. how to import my own modules in a project? in block or python modes?

      1 Reply Last reply Reply Quote 0
      • IAMLIUBOI
        IAMLIUBO
        last edited by

        Hi @Alexander ,
        First you may need create your module file(like myModules.py) on UIFlow,and create some block for your modules.
        0_1622509885440_2021-06-01_09-09.png

        Then make some block for your modules.
        0_1622509955738_2021-06-01_09-12.png

        Make some blocks on this workspace.
        0_1622510085086_2021-06-01_09-14.png

        When you are finished, you can click the download button in the lower right corner, and then open the downloaded m5b file in UIFlow.
        0_1622510331971_2021-06-01_09-18.png

        1 Reply Last reply Reply Quote 0
        • A
          Alexander
          last edited by

          Thank you.

          1 Reply Last reply Reply Quote 0
          • A
            Alexander
            last edited by

            I have a file.py. There are 20 custom functions in the file. This is a lot of code. Many of the functions call each other in calculations.
            In any new M5flow project, I just want to write "import file" first. And that's all.
            I don't want to rewrite all the functions separately for the M5flow. Or insert all this code into each new project manually. Or create blocks for each function.
            I saved the file to the device manager file. But still importing the file doesn't work.
            It seemed to me that there should be a simple and obvious solution. This is all very strange.
            maybe I just need to save the file in the appropriate format in the appropriate directory Uim5flow installed on the pc?

            G 1 Reply Last reply Reply Quote 0
            • G
              Gaviota @Alexander
              last edited by

              @alexander you have to store it on the M5stack in the directory where the main.py file is located and use it with python code in execute blocks.

              A lot of nice M5Stack stuff :) ....

              A 1 Reply Last reply Reply Quote 0
              • A
                Alexander @Gaviota
                last edited by

                @gaviota I'm trying to. But M5stack:"ERROR no module named"
                Until I understand what is wrong.

                G 1 Reply Last reply Reply Quote 1
                • G
                  Gaviota @Alexander
                  last edited by

                  @alexander try visual studio code (vscode) to import your module in the directory where you can find also the file main.py. Tutorials for using m5stack with vscode are located on the m5stack-youtoube-channel https://www.youtube.com/channel/UCozgFVglWYQXbvTmGyS739w e.g. this video: https://www.youtube.com/watch?v=Y9pOWgsNgKk
                  0_1623174429537_vscode_m5stack.jpg

                  A lot of nice M5Stack stuff :) ....

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    Alexander @Gaviota
                    last edited by

                    @gaviota Well thank you.
                    I'm tired of my own inability to solve this problem. So far, I just threw all the functions into the project.
                    Later I will do so, as you advise.

                    1 Reply Last reply Reply Quote 0
                    • D
                      democrazia
                      last edited by

                      Ok it's an old one but as I've found a solution...

                      1- Write your function code in test_code1.py for example, with a function dazi() inside.
                      2- Write your program code and on the top :
                      from apps import test_code1
                      3- when you want to use your dazi function, write then test_code1.dazi('.........../......')

                      It's working for me.

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