I tried the below in Jupiter, and it is working fine,
But one I tried to use at at file.mojo as:
from python import Python
# The Python way: `import requests as http`
let http = Python.import_module("requests")
# Now use numpy as if writing in Python
fn main():
let url = 'http://google.com'
let response = http.get(url)
let content = response.text
print(content)
I got the errors:
/home/hajsf/mojo/python.mojo:1:20: error: recursive reference to declaration
from python import Python
^
/home/hajsf/mojo/python.mojo:1:6: note: previously used here
from python import Python
^
/home/hajsf/mojo/python.mojo:1:1: error: 'object' does not refer to a package or module
from python import Python
^
mojo: error: failed to parse the provided Mojo

The
recursive reference to declarationcomes from your file being calledpython.mojo, if you rename it and fix this you will getcannot call function that may raise in a context that cannot raise, to fix this one the import of the module has to be inside a function that can catch exceptions, like:the
raisesaftermain()is the important part, point 4 from here.