CMake error in CLion: python ImportError: cannot import name 'Pattern'

Hi,

In terminal, ‘./yb_build.sh release’, ‘./yb_build.sh’ and ‘YB_USE_NINJA=0 ./yb_build.sh’ succeed. But in CLion, the CMake output error message as below. I am using CLion 2022.3.2 on CentOS 7.9, with yugabyte-db source code version ‘Commit d7afbc66 by SB YB, 11/23/2022 02:31 PM committed 11/23/2022 04:05 PM’.

Any other configuration needed for CLion?

/var/lib/snapd/snap/clion/222/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_BUILD_TYPE=Debug -S /root/code/yugabyte-db -B /root/code/yugabyte-db/build/debug-clang-dynamic
-- CMAKE_SYSTEM_INFO_FILE: Platform/Linux
-- CMAKE_SYSTEM_NAME:      Linux
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- CMAKE_SYSTEM:           Linux-3.10.0-1160.80.1.el7.x86_64
-- CMAKE_VERSION:          3.24.2
-- PRECOMPILED HEADERS:    OFF
Will build tests by default
YB_BUILD_TYPE: debug
YB_LINKING_TYPE: dynamic
CMAKE_MAKE_PROGRAM: /usr/bin/gmake
YB_SRC_ROOT: /root/code/yugabyte-db
YB_THIRDPARTY_DIR: /root/code/yugabyte-db/thirdparty
YB_BUILD_ROOT: /root/code/yugabyte-db/build/debug-clang-dynamic
YB_TARGET_ARCH: x86_64
Detected the number of logical CPUs: 4
Using shared library suffix '.so'.
CMAKE_C_COMPILER=/usr/bin/cc
CMAKE_CXX_COMPILER=/usr/bin/c++
LATEST SYMLINK PATH: /root/code/yugabyte-db/build/latest
YB_COMPILER_TYPE env var: clang
CMAKE_CXX_COMPILER=/usr/bin/c++
Compiler version information:
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 

Selected compiler family 'gcc', version '4.8.5'
THIRDPARTY_INSTRUMENTATION_TYPE=uninstrumented
Invoking build_thirdparty.sh with these arguments: --build-type;uninstrumented
+ cd /root/code/yugabyte-db/thirdparty
+ pip3 install --quiet -r requirements.txt

Logging to /root/logs/build_thirdparty_2023-02-04T00_23_15.log (linked to build_thirdparty_latest.log)

+ python3 /root/code/yugabyte-db/thirdparty/python/yugabyte_db_thirdparty/yb_build_thirdparty_main.py --build-type uninstrumented
Traceback (most recent call last):
  File "/root/code/yugabyte-db/thirdparty/python/yugabyte_db_thirdparty/yb_build_thirdparty_main.py", line 23, in <module>
    from yugabyte_db_thirdparty.builder import Builder
  File "/root/code/yugabyte-db/thirdparty/python/yugabyte_db_thirdparty/builder.py", line 24, in <module>
    from re import Pattern
ImportError: cannot import name 'Pattern'

Log saved to /root/logs/build_thirdparty_2023-02-04T00_23_15.log

CMake Error at CMakeLists.txt:233 (message):
  Thirdparty was built unsuccessfully, terminating.


-- Configuring incomplete, errors occurred!
See also "/root/code/yugabyte-db/build/debug-clang-dynamic/CMakeFiles/CMakeOutput.log".

[Failed to reload]

By the way, I need to use proxy to build yugabyte-db.

So in terminal, I set:
export http_proxy=socks5://127.0.0.1:1089
export https_proxy=$http_proxy

And in CLion, the configuration:

For python in CLion:


CMake in CLion:

@liubaogang

Note that Python 3.6 is EOL. Try to use at least 3.7

cc @svarnau

I will update to Python 3.7 later, since recent yugabyte-db source code can not be compiled with Python 3.6 in terminal.

For yugabyte-db source code version ‘Commit d7afbc66 by SB YB, 11/23/2022 02:31 PM committed 11/23/2022 04:05 PM’, Python 3.6 works well for buiding in terminal. I just do not know why the source code can not be built in CLion.

By adding environment variable “PYTHONPATH=/root/code/yugabyte-db/build/venv/lib/python3.6/site-packages/” in CLion, the problem disappear. (Another problem “pip._vendor.requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support” occurs which is not related with this problem.)

Not sure whether this is the right solution.

I found the solution through searching “PYTHONPATH” in source code of yugabyte-db in CLion, and execute ’ find . -name “*.py” -print | xargs grep -w “Pattern” ’ in yugabyte-db source code root path, and then tried to set environment variable “PYTHONPATH” in CLion using several possible path value one by one.