I tried installing on sensor rts TensorRT 7 for python 3 but got the following error::
root@2f2df21271b3:/opt/onnx-tensorrt/onnx-tensorrt# python3 setup.py build
Namespace(action=['build'], build_lib=None, include_dirs=None)
running build
running build_py
running build_ext
building 'onnx_tensorrt.parser._nv_onnx_parser_bindings' extension
swigging nv_onnx_parser_bindings.i to nv_onnx_parser_bindings_wrap.cpp
swig -python -c++ -modern -builtin -o nv_onnx_parser_bindings_wrap.cpp nv_onnx_parser_bindings.i
NvOnnxParser.h:213: Error: Syntax error in input(1).
error: command 'swig' failed with exit status 1
Hi, I met the same problem. Have you found out any solution? @Semihal
@1LOVESJohnny , Hi!
Unfortunately not :(
@1LOVESJohnny , I still use without Python3, just using bash: command onnx2trt.
@Semihal Thanks for your reply! I just tried to use 'onnx2trt' directly, but I met another problem:
CUDA initialization failure with error 35. Please check your CUDA installation.
Have you ever met this?
Hi all, I found a way to get it to work (not sure if it's a hack or not). Add #define TENSORRTAPI at the top of NvOnnxParser.h, and re-run python setup.py install. I believe the error comes from swig seeing a syntax error with TENSORRTAPI.
@1LOVESJohnny @Semihal
@peasant98 Thanks! I'll give it a try today. BTW, I solved my CUDA problem:
@Semihal Thanks for your reply! I just tried to use 'onnx2trt' directly, but I met another problem:
CUDA initialization failure with error 35. Please check your CUDA installation.Have you ever met this?
by updating my local environment from CUDA 10.0 to 10.2. Then the problem is gone.
@1LOVESJohnny, hi!
Unfortunately, I don't have the ability to upgrade the version.
sudo apt-get install swig
@peasant98 hi,i added #define TENSORRTAPI and i have finish executed python setup.py build,but when i do python setup.py install,i got a error follow:
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
Traceback (most recent call last):
File "setup.py", line 108, in <module>
"pycuda",
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/install.py", line 67, in run
self.do_egg_install()
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/install.py", line 109, in do_egg_install
self.run_command('bdist_egg')
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 209, in run
os.path.join(archive_root, 'EGG-INFO'), self.zip_safe()
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 245, in zip_safe
return analyze_egg(self.bdist_dir, self.stubs)
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 355, in analyze_egg
safe = scan_module(egg_dir, base, name, stubs) and safe
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 395, in scan_module
symbols = dict.fromkeys(iter_symbols(code))
File "/usr_data/cason/thirdParty/anaconda/Anaconda3_install/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 414, in iter_symbols
for name in code.co_names:
AttributeError: 'int' object has no attribute 'co_names'
@Kevin-Delnoije , Hi! Swig is installed.
@peasant98 i finished it ,thx,it's because my setuptools' version it too old
Hi all, I found a way to get it to work (not sure if it's a hack or not). Add
#define TENSORRTAPIat the top ofNvOnnxParser.h, and re-runpython setup.py install. I believe the error comes fromswigseeing a syntax error withTENSORRTAPI.
Thanks so much!
It worked for me!!!
Applied patch
--- a/NvOnnxParser.h
+++ b/NvOnnxParser.h
@@ -31,6 +31,10 @@
#define NV_ONNX_PARSER_MINOR 1
#define NV_ONNX_PARSER_PATCH 0
+#ifndef TENSORRTAPI
+#define TENSORRTAPI
+#endif // TENSORRTAPI
+
static const int NV_ONNX_PARSER_VERSION = ((NV_ONNX_PARSER_MAJOR * 10000) + (NV_ONNX_PARSER_MINOR * 100) + NV_ONNX_PARSER_PATCH);
//! \typedef SubGraph_t
diff --git a/setup.py b/setup.py
index 8ffa543..d6244a3 100644
--- a/setup.py
+++ b/setup.py
@@ -59,10 +59,11 @@ EXTRA_COMPILE_ARGS = [
'-std=c++11',
'-DUNIX',
'-D__UNIX',
- '-m64',
'-fPIC',
'-O2',
'-w',
+ '-march=armv8-a+crypto',
+ '-mcpu=cortex-a57+crypto',
'-fmessage-length=0',
'-fno-strict-aliasing',
'-D_FORTIFY_SOURCE=2',
then
sudo /usr/bin/python3 setup.py install
/usr/bin/python3 -c 'import onnx_tensorrt.backend as backend'
@brianegge How to I apply this patch ?
You can apply with the patch command, but for something small like this, just edit each file. Delete the lines showing a '-' in front and add the lines with a '+'.
After changing .... I have received the following error.

Just to confirm, before changing the error that I have seems to be the same as the topic of this issue, as shown below:

Here, I have also attached the scripts that I have made changed according to your comments.
Here, I attached them as .txt because I could not attached them with the original .py and .h
Sorry, my patch is for compiling on Jetson Nano. This patch won't help with x86.
I've recently modernized the setup.py installation script in https://github.com/onnx/onnx-tensorrt/pull/559. Can you try running the updated setup.py?
Closing due to inactivity - please upgrade to the latest TRT version and try installing the python library again. If that doesn't work, feel free to open a new issue.
Most helpful comment
Hi all, I found a way to get it to work (not sure if it's a hack or not). Add
#define TENSORRTAPIat the top ofNvOnnxParser.h, and re-runpython setup.py install. I believe the error comes fromswigseeing a syntax error withTENSORRTAPI.