Closed SirWaffle closed 10 months ago
Also check that all deps like z3 are into the same folder than triton.pyd
I copied and pasted this set of files in a few places.... the capstone DLL the lib Z3 dll the triton DLL i also duplicated all of them, and changed the extension to pyd
I get this error when trying to import triton from the vcpkg: Python.Runtime.PythonException: 'ImportError : dynamic module does not define module export function (PyInit_triton)'
using the artifacts for x64 from the build (from https://ci.appveyor.com/project/JonathanSalwan/triton/history) results in this error: Python.Runtime.PythonException: 'ModuleNotFoundError : No module named 'triton.language'; 'triton' is not a package'
any ideas?
PyInit_triton
makes me think about an issue around Python version (compile vs runtime). Is the Python version used during the compile is the same than the one used at runtime?
Hello, dear friends! Pretty much the same situation installing triton and referencing it from python script. Could somebody in the name of charity and goodwill explain how to handle this problem? Detailed instruction would be very much appreciated since i am out of options after trying all recommended steps... Thanks in advance!
Sorry guys, I can't help you on that side as i do not have a Windows on hand.
The last time I built it for Windows, I downloaded the source and all the dependencies (LLVM, Z3, Capstone...) then I opened the folder with cmake-gui. You have to manually enable features and enter the paths to your downloaded libraries. You should also enable PYTHON_BINDINGS_AUTOCOMPLETE. Click configure until there are no errors then click generate and make sure you only have warnings and no errors. Then you can open the solution in VS. Build python-triton and triton_autocomplete. Now you should have the .pyd and .pyi files that you can copy to your python site-packages directory. If you get any errors while building you probably didn't set up the dependecies correctly in CMAKE.
Cher Andrix44! Well, that sounds like a really good answer! I shall definitely try it ASAP and then report back the results to the community! Thanks a lot!
Follow up for anyone as well, to build Release builds on Windows with pre-built LLVM support. Note: still running into issues when generating debug builds of my projects using Triton, but for Release builds it's fine.
option(ASAN "Enable the ASAN linking" OFF)
option(BITWUZLA_INTERFACE "Use Bitwuzla as SMT solver" OFF)
option(BUILD_SHARED_LIBS "Build a shared library" ON)
option(GCOV "Enable code coverage" OFF)
option(LLVM_INTERFACE "Use LLVM for lifting" ON)
option(MSVC_STATIC "Use statically-linked runtime library" OFF)
option(Z3_INTERFACE "Use Z3 as SMT solver" ON)
option(BOOST_INTERFACE "Use Boost as multiprecision library" OFF)
option(PYTHON_BINDINGS_AUTOCOMPLETE "Generate an autocomplete stub file" ON)
I'm using PowerShell to set the dependencies as such, but you can readily adjust this to your build environment.
$BuildDir = "C:\code\triton\build"
# ---------------------------------------------------------------------------------
# z3 pre-built dependencies
# > pre-build: https://github.com/Z3Prover/z3/releases/download/z3-4.8.9/z3-4.8.9-x64-win.zip
# ---------------------------------------------------------------------------------
$Z3_INCLUDE_DIRS = "$BuildDir\z3\include"
$Z3_LIBRARIES_DIR = "$BuildDir\z3\bin"
$Z3_LIBRARIES = "$Z3_LIBRARIES_DIR\libz3.lib"
# ---------------------------------------------------------------------------------
# capstone 4.0.2 pre-built dependencies
# > build first, straightforward
# ---------------------------------------------------------------------------------
$CAPSTONE_INCLUDE_DIRS = "$BuildDir\capstone-4.0.2\include"
$CAPSTONE_LIBRARIES = "$BuildDir\capstone-4.0.2\msvc\x64\Release\capstone.lib"
# ---------------------------------------------------------------------------------
# LLVM15 pre-installed
# > https://github.com/LLVMParty/REVIDE/releases/download/libraries/llvm-15.0.3-win64.7z
# ---------------------------------------------------------------------------------
$LLVM_PREFIX = "C:\code\llvm-15.0.3-win64"
$LLVM_DIR = "$LLVM_DIR\lib\cmake\llvm" # needs to find LLVMConfig.cmake
NOTE: for LLVM, he has a hardcoded path for diaguids.pdb
that could cause an issue when building. You can adjust to your build environment by modifying the LLVMExports.cmake
file or the .csprojx
file after running cmake
.
> llvm-15.0.3-win64
kd > rg "diaguids"
lib/cmake\llvm\LLVMExports.cmake
406: INTERFACE_LINK_LIBRARIES "c:/Program Files/Microsoft Visual Studio/2022/Community/DIA SDK/lib/amd64/diaguids.lib;LLVMBinaryFormat;LLVMObject;LLVMSupport;LLVMDebugInfoCodeView;LLVMDebugInfoMSF"
Then generate the build scripts as such (targeting Python11 here):
cmake -DLLVM_INTERFACE=ON -DCMAKE_PREFIX_PATH="$LLVM_PREFIX" -DLLVM_DIR="$LLVM_DIR" -DPYTHON_VERSION="3.11" -DCAPSTONE_INCLUDE_DIRS="$CAPSTONE_INCLUDE_DIRS" -DCAPSTONE_LIBRARIES="$CAPSTONE_LIBRARIES" -DZ3_INCLUDE_DIRS="$Z3_INCLUDE_DIRS" -DZ3_LIBRARIES_DIR="$Z3_LIBRARIES_DIR".. -A x64
msbuild C:\code\triton\build\triton.sln /property:Configuration=Release /property:Platform=x64 /t:triton /t:python-triton /m:3
For both builds, the native and Python, make sure libz3.dll
is always accessible, since it's a direct dependency.
Awesome, thanks a lot for this feedback!
How do you compile the latest llvm,The official installer does not have a complete list of cmake files
Hello! I asked a very similar question here: Their response was priceless!
I am unsure how to properly install triton in windows. What I've done:
now im left unsure what to do. I saw on a previous issue, that the built DLL needs to be renamed to *.pyd and placed in the python path, which I have done. However, I am still unable to import and use triton.
I tried to pip install . inside of the triton checkout, but package install fails due to the wheel failing.