Comments (5)
Thanks - there I confused myself with package versions and virtual environments - with the new version, everything works fine!
from httpimport.
To get this to work again, I had to go all the way back to version 0.7.2 ...
from httpimport.
Hello @LukasWallrich
Thanks a lot for making this Issue! It is the proper chance to document this and make it searchable for others that will certainly have the same problem!
So, after 0.7.2
the syntax of all function signatures changed (for reasons documented here: #39 (comment)). In this answer I'll demonstrate the difference and the way to fix it.
0.7.2
You code snippet should work:
>>> import httpimport
>>> httpimport.__version__
'0.7.2'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>>
>>> with httpimport.remote_repo(["Gmodel"], url):
... from Gmodel import GProblem
...
>>> GProblem
<class 'Gmodel.GProblem'>
>=1.0.0
Your code should fail with the error in the title:
>>> import httpimport
>>> httpimport.__version__
'1.0.0'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>>
>>> with httpimport.remote_repo(["Gmodel"], url):
... from Gmodel import GProblem
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
[...]
line 254, in __init__
self.url = url if not url.endswith('/') else url[:-1]
AttributeError: 'list' object has no attribute 'endswith'
So what happens?
The remote_repo
function used to accept a list
as a mandatory parameter and a str
(the url
). After 1.0.0
, the list
parameter was removed. So now it only accepts the url
.
The Fix
Just removing the ["Gmodel"]
(the first parameter) from your code *would fix it:
>>> import httpimport
>>> httpimport.__version__
'1.3.0'
>>> url = "https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/"
>>> with httpimport.remote_repo(url): # <-------------- check out the new syntax
... from Gmodel import GProblem
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: cannot import name 'GProblem' from 'Gmodel' (https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/Gmodel.py)
>>>
Yet, you are using the same syntax in the Gist code itself, as shown below:
https://gist.githubusercontent.com/LukasWallrich/42dea3211f0bde452781dd9b69c8199a/raw/Gmodel.py - line 1
:
# Used this to avoid duplicating files
import httpimport
url = "https://gist.githubusercontent.com/LukasWallrich/05f445821fbae694b37a205dc08b2b4f/raw/"
with httpimport.remote_repo(["HPmodel"], url):
from HPmodel import HPProblem, PSAgent
[...]
so it fails to import the module using >=1.0.0
as it fetches the Gist code, tries to execute it (to load the new module) and halts with a syntax error in the module code itself.
If you also remove the ["HPmodel"]
parameter from the Gist code, it will be able to run using the latest version (1.3.0
at time of writing).
I hope I helped! This is what breaking changes do to a project...
from httpimport.
Ah, ok - that makes sense. Thank you!
Unfortunately, it still does not work.
If I run
import httpimport
url = "https://gist.githubusercontent.com/LukasWallrich/05f445821fbae694b37a205dc08b2b4f/raw/"
with httpimport.remote_repo(url):
from HPmodel import HPProblem, PSAgent
I get Exception: Plain HTTP URL provided with 'httpimport.INSECURE' not set
- which is rather confusing since the URL is obviously not plain HTML ...
from httpimport.
Plain HTTP URL provided with 'httpimport.INSECURE' not set
This log message doesn't even exist in the >=1.0.0
version! Try updating to 1.3.0
and running again!
What actually happened:
This comes from 0.7.2
:
https://github.com/operatorequals/httpimport/blob/0.7.2/httpimport.py#L97
and happens as remote_repo
in this version has a default value for the url
parameter, which is http://...
(you can see here: https://github.com/operatorequals/httpimport/blob/0.7.2/httpimport.py#L329). The whole API is unusable - that's why I changed it!
from httpimport.
Related Issues (20)
- Old module is imported when online file is changed HOT 2
- I encountered the following error when using the prompt HOT 1
- Support packages with shared object files HOT 2
- New version 0.9.2 breaks loading of joblib pickled model HOT 5
- Relative Path Importing/incorrect import package HOT 2
- Add support for module import directly from PyPI HOT 1
- Problem in Google Colab HOT 4
- Support Gitea Service
- attribute error module 'passman' has no attribute 'list_profiles' HOT 2
- Support for Gitlab private repos HOT 9
- import public github HOT 4
- How do I import from private github repo? HOT 3
- can't access private repo from github HOT 4
- AttributeError - unlcear how to import a Class from a module HOT 6
- Not supported from package.module import class HOT 9
- PyPIImporter should be able to use proxy
- Python 3.12 Support HOT 2
- Load a python script that contains a main function HOT 13
- Importing libraries with different installation name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from httpimport.