I’m trying to use the Modal
class from the modal
module. I’ve successfully installed the module using pip:
pip install modal
Python recognizes the modal module, but it doesn’t recognize the Modal
class when I run the following line:
from modal import Modal
How can I properly import Modal in a Python script?
The Modal
class does not exist in the current modal
module. I haven’t used this package in a while, but I feel like it may have in an older version.
Either way, the correct way to create an instance of the modal client is to use the App
class.
import modal
app = modal.App("example-hello-world")
This is right from their hello world example.
Then, every function just uses app
for a decorator:
@app.function()
def f(i):
if i % 2 == 0:
print("hello", i)
else:
print("world", i, file=sys.stderr)
return i * i
(Once again, this is copy paste from the docs)
Modal’s docs are really good. I see you have applied the batch-processing
tag to your post. After looking at the hello world example, consider looking at the scaling out gide.
I don’t know what your specific problem is without any more context, so I can’t do much more than guess that these suggestions will be helpful. Once again, modal has really good documentation and examples.