exographicskip
exographicskip
MModular
Created by exographicskip on 1/6/2024 in #questions
Python.import_module not working as expected
That did it! Thank you! This is what I landed on fwiw
#!/usr/bin/env mojo

fn main():
from python import Python

# let is an immutable variable
let hello = "Hello World!"
print(hello)

# var is a mutable variable
try:
let builtins = Python.import_module("builtins")
var name = str(builtins.input("What is your name? "))
print("Hello", name)
name = "World" # mutate the variable
print("Hello", name)
except:
print("Unable to import Python module 'builtins'")
#!/usr/bin/env mojo

fn main():
from python import Python

# let is an immutable variable
let hello = "Hello World!"
print(hello)

# var is a mutable variable
try:
let builtins = Python.import_module("builtins")
var name = str(builtins.input("What is your name? "))
print("Hello", name)
name = "World" # mutate the variable
print("Hello", name)
except:
print("Unable to import Python module 'builtins'")
5 replies
MModular
Created by exographicskip on 1/6/2024 in #questions
Python.import_module not working as expected
Compiled version
λ ./hello
Hello World!
Mojo/Python interoperability error: Unable to locate a suitable libpython, please set `MOJO_PYTHON_LIBRARY`
Segmentation fault: 11
λ ./hello
Hello World!
Mojo/Python interoperability error: Unable to locate a suitable libpython, please set `MOJO_PYTHON_LIBRARY`
Segmentation fault: 11
Which is interesting bc I set
export MOJO_PYTHON_LIBRARY=/Users/lance/.asdf/installs/python/3.11.6/lib/libpython3.11.dylib
export MOJO_PYTHON_LIBRARY=/Users/lance/.asdf/installs/python/3.11.6/lib/libpython3.11.dylib
5 replies
MModular
Created by exographicskip on 1/6/2024 in #questions
Python.import_module not working as expected
Debug console shows
Running initCommands:
(lldb) settings set target.show-hex-variable-values-with-leading-zeroes false
(lldb) settings set target.process.optimization-warnings false
(lldb) plugin load '/Users/lance/.modular/pkg/packages.modular.com_mojo/lib/libMojoLLDB.dylib'
(lldb) command script import /Users/lance/.modular/pkg/packages.modular.com_mojo/lib/lldb-visualizers/lldbDataFormatters.py
error: module importing failed: This script interpreter does not support importing modules.
(lldb) command script import /Users/lance/.modular/pkg/packages.modular.com_mojo/lib/lldb-visualizers/mlirDataFormatters.py
error: module importing failed: This script interpreter does not support importing modules.
Hello World!
Error: Python not found
Hello Mojo
Hello Mojo
Running initCommands:
(lldb) settings set target.show-hex-variable-values-with-leading-zeroes false
(lldb) settings set target.process.optimization-warnings false
(lldb) plugin load '/Users/lance/.modular/pkg/packages.modular.com_mojo/lib/libMojoLLDB.dylib'
(lldb) command script import /Users/lance/.modular/pkg/packages.modular.com_mojo/lib/lldb-visualizers/lldbDataFormatters.py
error: module importing failed: This script interpreter does not support importing modules.
(lldb) command script import /Users/lance/.modular/pkg/packages.modular.com_mojo/lib/lldb-visualizers/mlirDataFormatters.py
error: module importing failed: This script interpreter does not support importing modules.
Hello World!
Error: Python not found
Hello Mojo
Hello Mojo
5 replies