Build fail with 'TypeError : cannot use a string pattern on a bytes-like object'
Platform: any (aarch64, armv7, x86_64)
Operating System: openSUSE
Problem description: While trying to build with openCL, on openSUSE Tumbleweed (rolling release) or Leap 15.0+ (stables), I get:
[ 50s] scons: *** [build/src/core/CL/cl_kernels/absdiff.clembed] TypeError : cannot use a string pattern on a bytes-like object
Previous openSUSE Leap versions are fine.
What compiler version are you using ? Could you try one of the ones that have been tested ?
https://arm-software.github.io/ComputeLibrary/v18.11/index.xhtml#S3_2_linux
What compiler version are you using ?
It breaks with GCC8/scons 3.0.2 and GCC7/scons 7.0.1.
Sorry, actually it looks like a Python / Scons error: what version of Python are you using ? Do you have a python backtrace ?
This is Python 3.6.5. I should have included the full backtrace, sorry. Here it is:
[ 50s] scons: *** [build/src/core/CL/cl_kernels/absdiff.clembed] TypeError : cannot use a string pattern on a bytes-like object
[ 50s] Traceback (most recent call last):
[ 50s] File "/usr/lib/python3.6/site-packages/SCons/Action.py", line 1202, in execute
[ 50s] result = self.execfunction(target=target, source=rsources, env=env)
[ 50s] File "/home/abuild/rpmbuild/BUILD/ComputeLibrary-18.11/SConscript", line 89, in resolve_includes
[ 50s] found = pattern.search(line)
[ 50s] TypeError: cannot use a string pattern on a bytes-like object
[ 51s] scons: building terminated because of errors.
We'll have a look, in the meantime can you try to force SCons to use python2 ? (By editing /usr/bin/scons by example and changing the first line to /usr/bin/python2)
Hi @ggardet, have you solved the problem?
Hi - I have the exact same issue. Anyone figured this out?
If you try to force python2 the error becomes:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: `arm_compute' is up to date.
scons: `support' is up to date.
scons: *** [opencl-1.2-stubs/opencl_stubs.c] ValueError : unsupported pickle protocol: 4
scons: building terminated because of errors.
Basically what appears to be happening is that byte objects are being used all over the place instead of strings. For example, if you go to line 89 and change it to: found = pattern.search(line.decode("utf-8"))
it will move on, but you will get a similar error on line 114.
I don't really understand scons all that much, but why is it reading the files into the python interpreter to build them? Are they being manipulated on the fly?
Could you provide the exact scons command?
Then also output of the following commands
scons --version
gcc --version
g++ --version
uname -a
Best, Manuel
rockpro64 ~ # scons --version SCons by Steven Knight et al.: script: v3.0.4.3a41ed6b288cee8d085373ad7fa02894e1903864, 2019-01-23 17:30:35, by bdeegan on kufra engine: v3.0.4.3a41ed6b288cee8d085373ad7fa02894e1903864, 2019-01-23 17:30:35, by bdeegan on kufra engine path: ['/usr/lib64/python3.6/site-packages/SCons'] Copyright (c) 2001 - 2019 The SCons Foundation
rockpro64 ~ # gcc --version gcc (Gentoo 8.2.0-r6 p1.7) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
rockpro64 ~ # g++ --version g++ (Gentoo 8.2.0-r6 p1.7) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
rockpro64 ~ # uname -a Linux rockpro64 4.20.0-rc6-106496-g6b3dd2a83c96-dirty #3 SMP PREEMPT Mon Jan 21 15:49:16 MST 2019 aarch64 GNU/Linux
I am guessing you are compiling on the board. Have you tried cross-compiling on local machine and then upload the files on the board?
Thanks, Manuel
Same thing happens. the problem is in python and scons. Whoever set this up is reading in a bunch of files as binary objects and not converting them properly. Here is my question - does it work for you guys out at arm? If so, what are your:
scons --version gcc --version g++ --version
and what version of python are you using with scons? I assume it works for you, unless someone has made checkins and hasn't looked at what they built. The issue is in scons and python, so this should be easy to fix.
Thanks!
Yes we have a reference environment and it is the one we use, you can find everything here: https://arm-software.github.io/ComputeLibrary/v18.11/index.xhtml
We usually crosscompile and upload the files on a board. Step by step:
$ scons --version
SCons by Steven Knight et al.:
script: v2.4.1.rel_2.4.1:3453:73fefd3ea0b0, 2015/11/09 03:25:05, by bdba
This is the scons command we use:
os=linux arch=arm64-v8a Werror=1 mode=release neon=1 opencl=1 examples=1 validation_tests=1 benchmark_tests=1 -j32`
Which uses the following compiler: aarch64-linux-gnu-g++ . So:
$ aarch64-linux-gnu-g++ --version
aarch64-linux-gnu-g++ (Linaro GCC 6.3-2017.05) 6.3.1 20170404
Also you might not want to change your environment python and scons version, in this sense you can setup a virtual machine with this OS:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
Let us know if you keep having problems Thanks
Hi, @ggardet @AnthonyARM @tenspd137 @ManubARM I faced the same problem, I'm building the library on windows, I changed the CXX and C compiler to
env['CC'] = "~/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
env['CXX'] = "~/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe"
then I faced the error
Traceback (most recent call last):
File "d:\software\anaconda\envs\onnx\lib\site-packages\scons\SCons\Action.py", line 1202, in execute
result = self.execfunction(target=target, source=rsources, env=env)
File "D:\code\armnn-devenv\ComputeLibrary\SConscript", line 89, in resolve_includes
found = pattern.search(line)
TypeError: cannot use a string pattern on a bytes-like object
then I changed to python2.7, I got
File "D:\software\anaconda\envs\python2\Scripts\scons", line 204, in <module>
scons: Building targets ...
scons: `arm_compute' is up to date.
scons: `support' is up to date.
scons: *** [opencl-1.2-stubs\opencl_stubs.c] ValueError : unsupported pickle protocol: 4
scons: building terminated because of errors.
Is it possible to build library on windows?
scons: *** [opencl-1.2-stubs\opencl_stubs.c] ValueError : unsupported pickle protocol: 4
This is likely due to some residual Python 3 files, make sure your folder is clean from any pyc files, etc.
We don't support building natively on Windows but it should be pretty straight forward using Bash on Windows or a Virtual Machine.
Regarding
TypeError: cannot use a string pattern on a bytes-like object
Could you try this patch and let us know if it fixes the issue:
diff --git a/SConscript b/SConscript
index e57dd2390..9b5653d97 100644
--- a/SConscript
+++ b/SConscript
@@ -70,7 +70,7 @@ def resolve_includes(target, source, env):
for i in range(len(source)):
src = source[i]
dst = target[i]
- contents = src.get_contents().splitlines()
+ contents = src.get_contents().decode('utf-8').splitlines()
entry = FileEntry(target_name=dst, file_contents=contents)
files.append((os.path.basename(src.get_path()),entry))
Thanks @AnthonyARM for your help.
I'm building ArmNN on windows using the clang in windows ndk, there's some problem in linking the armnn to armcompute reference. So I want to build the library using clang.exe in windows ndk.
I cleared the cache and used python2 to build the library, after builded some sources, I got an error below:
scons: *** [build\opencl-1.2-stubs\opencl_stubs.os] The system cannot find the file specified
scons: *** [build\src\core\AccessWindowAutoPadding.o] The system cannot find the file specified
scons: *** [build\src\core\AccessWindowStatic.o] The system cannot find the file specified
scons: *** [build\src\core\AccessWindowTranspose.o] The system cannot find the file specified
scons: *** [build\src\core\Error.o] The system cannot find the file specified
scons: *** [build\src\core\GPUTarget.o] The system cannot find the file specified
scons: *** [build\src\core\HOGInfo.o] The system cannot find the file specified
scons: *** [build\src\core\Helpers.o] The system cannot find the file specified
scons: *** [build\src\core\IAccessWindow.o] The system cannot find the file specified
scons: *** [build\src\core\IDistribution.o] The system cannot find the file specified
scons: *** [build\src\core\IDistribution1D.o] The system cannot find the file specified
scons: *** [build\src\core\IKernel.o] The system cannot find the file specified
scons: *** [build\src\core\ITensor.o] The system cannot find the file specified
scons: *** [build\src\core\MultiImageInfo.o] The system cannot find the file specified
scons: *** [build\src\core\PyramidInfo.o] The system cannot find the file specified
scons: building terminated because of errors.
Is there a chance I link the armnn in windows to the compute library?
it seems to the be encode/decode issue. I sovled the problem by take python2 rather than python3。 Explicitly decode the string might also work.
import chardet
encode_type = chardet.detect(html)
html = html.decode(encode_type['encoding'])
Regarding
TypeError: cannot use a string pattern on a bytes-like objectCould you try this patch and let us know if it fixes the issue:
diff --git a/SConscript b/SConscript index e57dd2390..9b5653d97 100644 --- a/SConscript +++ b/SConscript @@ -70,7 +70,7 @@ def resolve_includes(target, source, env): for i in range(len(source)): src = source[i] dst = target[i] - contents = src.get_contents().splitlines() + contents = src.get_contents().decode('utf-8').splitlines() entry = FileEntry(target_name=dst, file_contents=contents) files.append((os.path.basename(src.get_path()),entry))
It does fix the problem! Thanks. @AnthonyARM Do you want I do a PR or will you take care of it?