-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No callable attribute: exec [ValueError] #261
Comments
What does |
that one:
but I guess it might have been
I guess this is it, how do I fix it? |
You can specify path to libpython using |
tried both paths below (the first is the one given me by find_libpython, the second it looked reasonable to me by looking around in the folders): import nimpy
import nimpy / py_lib
#pyInitLibPath "/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/Python"
pyInitLibPath "/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib"
let py = pyBuiltinsModule()
discard py.exec("sum([1, 2, 3])") but the result is always an error of loading like this
not sure what I should use... |
Not sure, could it be because of architecture mismatch?
|
I went back this (sorry for the delay) and I think back then I had indeed an architecture mismatch (default python on Mac M1 is x86_64). I installed an arm python and now I have both my new python and my nim executable that are both I do get a different error now. For reference now I compile and run: import nimpy
import nimpy / py_lib
pyInitLibPath "/Library/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib"
let py = pyBuiltinsModule()
discard py.exec("sum([1, 2, 3])") and the error is:
checking architecture with file:
|
I'm having the same issue here. I used the
Output:
I don't really think this problem comes from different architecture Update: To make sure Update 2: According to the stackoverflow link, apparently we have to pass
|
So here's the working code of mine, Nim 1.6.0, nimpy 0.2.0
Solution found at https://blogs.mathworks.com/loren/2020/03/03/matlab-speaks-python/ |
got exec() working 🙂 import nimpy
import nimpy/py_lib
from std/envvars import getEnv , putEnv
let pythonDll_dirPath = "C:/python"
let pythonDll_filePath = pythonDll_dirPath & "/python3.dll"
let pathEnvVar_name = "Path"
let pathEnvVar_value = pythonDll_dirPath & ";" & getEnv( pathEnvVar_name )
putEnv( pathEnvVar_name , pathEnvVar_value )
# necessary for pyInitLibPath() to work
pyInitLibPath( pythonDll_filePath )
let sys_pyModule = pyImport("sys")
let builtins_pyModule = pyImport("builtins")
var topLevelDunderMain_pyModule = sys_pyModule.modules["__main__"]
var dunderDictOfTopLevelDunderMain_pyDict
= builtins_pyModule.getattr( topLevelDunderMain_pyModule , "__dict__" )
discard builtins_pyModule.exec( "print(42)" , dunderDictOfTopLevelDunderMain_pyDict )
echo( builtins_pyModule.str( pyGlobals() ) )
-> None therefore a working my environment : |
with a recent installation of nimpy on Mac (M1), the following does not work:
and throws error
.nimble/pkgs/nimpy-0.2.0/nimpy.nim(842) callMethodAux Error: unhandled exception: No callable attribute: exec [ValueError]
the only mention I found of
exec
in nimpy repo is in this test:nimpy/tests/tpyfromnim.nim
Line 251 in 1963283
(but exec is a command that works in python interpreter). I found out about the possibility of using
exec
from this: pietroppeter/nimib#83note that the readme example works fine
other info:
The text was updated successfully, but these errors were encountered: