Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'somePython' when using remote_repo #25

Closed
BrandonsAccount opened this issue Oct 17, 2019 · 4 comments
Closed

No module named 'somePython' when using remote_repo #25

BrandonsAccount opened this issue Oct 17, 2019 · 4 comments

Comments

@BrandonsAccount
Copy link

BrandonsAccount commented Oct 17, 2019

I can't seem to get remote_repo to work. I've tried accessing modules in my private Gitlab instance and an example module in Github. I keep getting "No module named x" error. I assume it has something to do with my code but I've tried a few different iterations with no luck. It would be nice to see a working example in the readme that pulls from a publicly available python package. The load() method also can't seem to find the module.

Here's a snippet.

#!/usr/bin/env python3
from httpimport import remote_repo
import httpimport
with remote_repo(['myPackage'], 'https://github.com/BillMills/python-package-example/blob/master/myPackage/'):
    import somePython
@operatorequals
Copy link
Owner

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).

@operatorequals
Copy link
Owner

Closing due to inactivity!

@AKHACKER-program4hack
Copy link

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

@operatorequals
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants