1

I'm trying to use py-script to show my own projects from github working. but it means that my functions need to access my github subfolders to work and I dont know how to...

This is the code I'm trying to use, it has a math lib reference that works fine, and my references to tables and tabelastoolkit lib that dont.

        <div class="codigo"> 
            <py-script>
                import math
                from https://github.com/capuadaniel/3d_science_plotter.git import base

                def t_binomial(N, k, alfa = 0.05, uni_bi = 2, p = 0.5 ):
                q = 1 - p
                h = z =  0.5
                if N > 25 and N*p*q >= 9:
                    z = (k + 0.5) - (N * p) / math.sqrt(N * p * q)
                elif N <= 35:
                    z = float('0.'+tabelas.D[N][k])
                else:
                    if k > N*p:
                        h = -0.5
            
                    z = ((k + h) - (N * p)) / math.sqrt(N * p * q)
                    z = tabelastoolkit.alfaconvert(z,'a') * uni_bi
                    p = alfa
            
                if z < p:
                    return f'z= {z} é menor que o nivel de significancia p={p} estabelecido, favorecendo H1'
                else:
                    return f'z= {z} é maior que o nivel de significancia p={p} estabelecido, favorecendo H0'


                t_binomial(18, 8)
            </py-script>
        </div>

Of course the line "from https://github.com/capuadaniel/3d_science_plotter.git import base" is the key, anyone already made anithing in this way?

  • as I know standard python can't `import` from github - it can only `install` module from GitHub. And as I know `` imports non-standard module directly from server `pypi.org` (which is used by `pip` to install modules) and it may not function to import from other servers. And for non-standard modules this also need to put name of this module in ` ` – furas May 31 '22 at 01:33
  • GitHub repositories are not Python packages. When you specify `https://github.com/capuadaniel/3d_science_plotter.git`, you will download the HTML home page for the repository. You are not downloading the repository. If the repo has **releases**, you can download the repo zip file, parse it in Python and then load it into the Python namespace. Edit your question to clearly state what you are trying to do. – John Hanley May 31 '22 at 03:06
  • @Wayne - PyScript and Jupyter are different products. – John Hanley May 31 '22 at 15:08
  • @Wayne - opinions and recommendations are off-topic on Stack Overflow. I understand what you are trying to do, but again PyScript and Jupyter are very different products and your concepts will not work with PyScript. In addition, Jupyter does not provide the features that PyScript does, so your recommendation has no value in that respect. – John Hanley May 31 '22 at 15:18
  • Was there ever an answer to this question of how to import python files stored on a github repo? – rhody Dec 20 '22 at 05:41

1 Answers1

0

if its a module we can import with pip like

pip install git+https://github.com/capuadaniel/3d_science_plotter.git

Good info here ==> pip install from git repo branch

Light
  • 147
  • 1
  • 4
  • You've confirmed this works with pyscript? – Wayne Jun 02 '22 at 15:14
  • Its very interesting, I tried on google colab and it donwt works, but I think its because my code has no __init__ its just a lot of functions for now. I will learn more about, it looks to be a good way. – Daniel Capua Dec 20 '22 at 19:49