wasmer-python icon indicating copy to clipboard operation
wasmer-python copied to clipboard

ImportError: cannot import name 'engine' from partially initialized module 'wasmer'

Open apoorvpandey0 opened this issue 2 years ago • 2 comments

I just installed wasmer and wasmer cranelift using these:

pip install wasmer
pip install wasmer-compiler-cranelift

I have copied a sample script from examples folder in this library

   
# A Wasm module can be compiled with multiple compilers.
#
# This example illustrates how to use the Cranelift compiler.
#
# You can run the example directly by executing in Wasmer root:
#
# ```shell
# $ python examples/compiler_cranelift.py
# ```
#
# Ready?

from wasmer import engine, wat2wasm, Store, Module, Instance
from wasmer_compiler_cranelift import Compiler

# Let's declare the Wasm module with the text representation.
wasm_bytes = wat2wasm(
    """
    (module
      (type $sum_t (func (param i32 i32) (result i32)))
      (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
        local.get $x
        local.get $y
        i32.add)
      (export "sum" (func $sum_f)))
    """
)

# Define the engine that will drive everything.
#
# In this case, the engine is `wasmer.engine.Universal` which roughly
# means that the executable code will live in memory.
#
# This is _the_ place to pass the compiler. Note that `Compiler` is
# not instantiated, we pass the class only.
engine = engine.Universal(Compiler)

# Create a store, that holds the engine.
store = Store(engine)

# Let's compile the Wasm module with the Cranelift compiler.
module = Module(store, wasm_bytes)

# Let's instantiate the Wasm module.
instance = Instance(module)

# Let's call the `sum` exported function.
sum = instance.exports.sum
results = sum(1, 2)

print(results)
assert results == 3

On running this script I get this error

ImportError: cannot import name 'engine' from partially initialized module 'wasmer' 

Am I missing something here?

apoorvpandey0 avatar Oct 15 '21 07:10 apoorvpandey0

As pointed out here this is due to keeping the name of the file as wasmer.py. Now I'm getting the same issue as some previous issues

raise ImportError("Wasmer is not available on this system")
ImportError: Wasmer is not available on this system

I'm running this on a Windows system.

apoorvpandey0 avatar Oct 15 '21 11:10 apoorvpandey0

Hi @apoorvpandey0,

I'd suggest checking if your Python version (the one corresponding to your pip commands you've referenced) is supported, as well as your OS version. This could be, for instance, a duplicate of this issue.

Another useful check might be to see if pip is the same as python -m pip (as you're installing packages via the former), as some people have multiple Python versions installed on the same system.

Good luck!

hristog avatar Jun 12 '22 07:06 hristog