Giter Club home page Giter Club logo

Comments (4)

operatorequals avatar operatorequals commented on May 21, 2024

Well, the Gitlab is a bit of a pain, and it has some known bugs. It works for some repos but not for all and it has to be re-examined and relaunched.

Yet, the code snippet you are posting does not work and there are reasons for that:

  • If you want to load from Github, then use the github_repo directly as it provides enough abstraction:
from httpimport import github_repo
import httpimport

with github_repo('BillMills', 'python-package-example', module='myPackage'):
    import myPackage.somePython

but this fails also with the following error:

Traceback (most recent call last):
  File "test2.py", line 7, in <module>
    import myPackage.somePython
  File "/Users/johntorakis/.virtualenvs/httpimport/lib/python3.7/site-packages/httpimport.py", line 254, in load_module
    exec(final_src, mod.__dict__)
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'somePython'

the __init__.py tries to import somePython.py without using the full module name.

My bet is that if you replace this line with import myPackage.somePython, the code I posted should work.

Why your code fails

the URL you are using makes httpimport to traverse from inside the package, so as it is looking for a package named myPackage in this directory, it fails.
Additionally, you need a URL that when appended with filenames (e.g somePython.py) it will return the raw file. Such URL for that Github repo is https://raw.githubusercontent.com/BillMills/python-package-example/master/myPackage/. Check the raw.githubusercontent.com domain.

If you replace the code with:

with remote_repo(['somePython'], 'https://raw.githubusercontent.com/BillMills/python-package-example/master/myPackage/'):
    import somePython

it will work.

For me it was:

>>> from httpimport import remote_repo
>>> import httpimport
>>> with remote_repo(['somePython'], 'https://raw.githubusercontent.com/BillMills/python-package-example/master/myPackage/'):
...     import somePython
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/johntorakis/.virtualenvs/httpimport/lib/python3.7/site-packages/httpimport.py", line 254, in load_module
    exec(final_src, mod.__dict__)
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

as somePython.py tries to import numpy in the first line, which I don't have (and it is not needed in the script anyway).

from httpimport.

operatorequals avatar operatorequals commented on May 21, 2024

Closing due to inactivity!

from httpimport.

AKHACKER-program4hack avatar AKHACKER-program4hack commented on May 21, 2024

I have run that code but i still have error in importing

this is my repo link

and this is my code

with httpimport.github_repo('AKHACKER-program4hack', 'searcher', branch='master'):
    import searcher.forsearch
    s = forsearch.Searcher()
    s.printuser()

And i am getting this error:

Traceback (most recent call last):
  File "/home/ak/Desktop/development/pythonwork/testing/httpimport/testing.py", line 8, in <module>
    s = forsearch.Searcher()
NameError: name 'forsearch' is not defined

Can you tell me what's the problem

from httpimport.

operatorequals avatar operatorequals commented on May 21, 2024

I have run that code but i still have error in importing

this is my repo link

and this is my code

with httpimport.github_repo('AKHACKER-program4hack', 'searcher', branch='master'):
    import searcher.forsearch
    s = forsearch.Searcher()
    s.printuser()

And i am getting this error:

Traceback (most recent call last):
  File "/home/ak/Desktop/development/pythonwork/testing/httpimport/testing.py", line 8, in <module>
    s = forsearch.Searcher()
NameError: name 'forsearch' is not defined

Can you tell me what's the problem

You are having a Python error, not related with httpimport.

with httpimport.github_repo('AKHACKER-program4hack', 'searcher', branch='master'):
    import searcher.forsearch
    s = searcher.forsearch.Searcher()
    s.printuser()

This works for me!

from httpimport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.