Maratyszcza/PeachPy

Getting "ImportError: No module named x86_64" when running simple code

bifunctor opened this issue ยท 9 comments

I have this simple code:

import peachpy
import peachpy.x86_64

x = peachpy.Argument(peachpy.int64_t)

with peachpy.x86_64.Function("Add4", (x,), peachpy.int64_t) as asm_function:
    peachpy.x86_64.LOAD.ARGUMENT(peachpy.x86_64.rax, x)
    peachpy.x86_64.ADD(peachpy.x86_64.rax, 4)
    peachpy.x86_64.RETURN(peachpy.x86_64.rax)

abi = peachpy.x86_64.abi.detect()
encoded_function = asm_function.finalize(abi).encode()
python_function = encoded_function.load()

# The JIT call
print(python_function(-100))

When I run this code, I get this error:

Traceback (most recent call last):
  File "C:/Users/Oround/Desktop/Tests.py", line 2, in <module>
    import peachpy.x86_64
ImportError: No module named x86_64

Why am I getting this error? Is there something I could do to fix it?

Try to reinstall PeachPy following the README

@Maratyszcza Thanks-- but sadly it din't work. I don't get the import error after that, but I get a different error:

TypeError: None is not an ABI object

What does peachpy.x86_64.abi.detect() return?

@Maratyszcza -- When I print it, I get None.

If it helps, I use windows 7.

@Maratyszcza -- This might be a little off topic, but is there a documentation? I tried looking for one, but couldn't find it.

Probably you're using 32-bit Python? The snippet you try to run loads a PeachPy function into the Python process, and its not possible to load 64-bit (x86-64) function into a 32-bit process on Windows.

@Maratyszcza -- I checked my IDLE, and found that you are right; Its 64-bit! Is there some way I could successfully run peachpy using the 32-bit version instead of switching to the 64-bit version?

You can use PeachPy in 32-bit Python (e.g. to generate an object file that you'd later link into an .exe), but if you want to load PeachPy function as a Python function (like you do in your code), there is no way around using 64-bit Python. This is because you can't execute code for a different architecture (x86-64) from a x86 process.