5

I'm trying to download re2 by the command pip install re2 and it gives me this:

Collecting re2
  Using cached re2-0.2.22.tar.gz
Building wheels for collected packages: re2
  Running setup.py bdist_wheel for re2 ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_tul1J/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpEx8yE1pip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_ext
  building 're2' extension
  creating build
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/re2.cpp -o build/temp.linux-x86_64-2.7/src/re2.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  src/re2.cpp:201:29: fatal error: re2/stringpiece.h: No such file or directory
   #include "re2/stringpiece.h"
                               ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for re2
  Running setup.py clean for re2
Failed to build re2
Installing collected packages: re2
  Running setup.py install for re2 ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_tul1J/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-qsPvRS-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 're2' extension
    creating build
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/re2.cpp -o build/temp.linux-x86_64-2.7/src/re2.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    src/re2.cpp:201:29: fatal error: re2/stringpiece.h: No such file or directory
     #include "re2/stringpiece.h"
                                 ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-_tul1J/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-qsPvRS-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-_tul1J/re2/

Why it isn't working? Or should I download re2 by other way?

NOTE: I figured out that re2 must have google's re2 c++ installed already, If that the problem, can you show me how can I install google's re2 c++ and re2 in simple way? I got confused from what they wrote about how to install.


After Trying MattDMo's Solution I got this:

Collecting re2
  Using cached re2-0.2.22.tar.gz
Building wheels for collected packages: re2
  Running setup.py bdist_wheel for re2 ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-azytbM/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpxFXFdmpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_ext
  building 're2' extension
  creating build
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/src
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include/python2.7 -c src/re2.cpp -o build/temp.linux-x86_64-2.7/src/re2.o
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  In file included from /usr/include/c++/4.9/mutex:35:0,
                   from /usr/local/include/re2/re2.h:184,
                   from src/re2.cpp:202:
  /usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   #error This file requires compiler and library support for the \
    ^
  In file included from src/re2.cpp:202:0:
  /usr/local/include/re2/re2.h:734:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
     mutable std::once_flag rprog_once_;
                  ^
  /usr/local/include/re2/re2.h:735:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
     mutable std::once_flag num_captures_once_;
                  ^
  /usr/local/include/re2/re2.h:736:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
     mutable std::once_flag named_groups_once_;
                  ^
  /usr/local/include/re2/re2.h:737:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
     mutable std::once_flag group_names_once_;
                  ^
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for re2
  Running setup.py clean for re2
Failed to build re2
Installing collected packages: re2
  Running setup.py install for re2 ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-azytbM/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hKOqNV-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 're2' extension
    creating build
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/local/include -I/usr/include/python2.7 -c src/re2.cpp -o build/temp.linux-x86_64-2.7/src/re2.o
    cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
    In file included from /usr/include/c++/4.9/mutex:35:0,
                     from /usr/local/include/re2/re2.h:184,
                     from src/re2.cpp:202:
    /usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
     #error This file requires compiler and library support for the \
      ^
    In file included from src/re2.cpp:202:0:
    /usr/local/include/re2/re2.h:734:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
       mutable std::once_flag rprog_once_;
                    ^
    /usr/local/include/re2/re2.h:735:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
       mutable std::once_flag num_captures_once_;
                    ^
    /usr/local/include/re2/re2.h:736:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
       mutable std::once_flag named_groups_once_;
                    ^
    /usr/local/include/re2/re2.h:737:16: error: ‘once_flag’ in namespace ‘std’ does not name a type
       mutable std::once_flag group_names_once_;
                    ^
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-azytbM/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hKOqNV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-azytbM/re2/
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
johndoe_asking
  • 141
  • 1
  • 3
  • 14

4 Answers4

7

If you are on ubuntu, sudo apt-get install libre2-dev is required prior to calling

pip install re2
roschach
  • 8,390
  • 14
  • 74
  • 124
Harri
  • 89
  • 1
  • 1
6

All you need to do is clone the libre2 Github repo along with the pyre2 Github repo (as the version on PyPI available to pip has errors in the code), build and install libre2 first, then build and install pyre2.

  1. Start your favorite terminal app.
  2. Make src directory in your $HOME for storing source code:

    mkdir ~/src
    
  3. Enter src dir:

    cd ~/src
    
  4. Clone repo (assuming you have git installed):

    git clone https://github.com/google/re2.git
    
  5. Enter re2 dir:

    cd re2
    
  6. Make:

    make
    
  7. Assuming no errors, make install:

    sudo make install
    
  8. Clone pyre2 github repo

    git clone https://github.com/axiak/pyre2.git ~/src/pyre2
    
  9. Switch to repo's directory:

    cd ~/src/pyre2
    
  10. Build:

    python setup.py build
    
  11. Install:

    sudo python setup.py install
    
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • 1
    Everything works except 8, it gives me that red text `Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-azytbM/re2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-hKOqNV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-azytbM/re2/ ` Also I think there's more error messages but it too long for comment. – johndoe_asking May 01 '16 at 18:10
  • @johndoe_asking I've tried building it myself on Ubuntu 16.04, and I'm running into the same errors as you. However, please see my updated answer. The release of `pyre2` on PyPI is from May 2015, however its github repo was last updated about 2 months ago. If you clone the repo and build from there, it should work, with some warnings that you can ignore. At least, it worked for me :) – MattDMo May 01 '16 at 21:10
  • The question is, if `pyre2` is valid as `re` for using adblockparser. The reason that I need `re2` it because in `adblockparser`, the use of it can make the filter work very much faster than the regular `re`. Anyway, you helped me a lot! Thanks and keep up the good work! – johndoe_asking May 02 '16 at 00:30
0

I faced a similar issue. For me the issue was that the bash_profile file was not properly configured.

To solve this problem:

Install jdk

Open ~/.bash_profile in any text editor or use vim ~/.bash_profile command

and add:

export JAVA_HOME=$(/usr/libexec/java_home)

Open a Terminal and run the source command to apply the changes:

source ~/.bash_profile

After this install re2 using pip

pip install re2

Corey
  • 835
  • 1
  • 9
  • 32
ria
  • 1
0

Since the package re2 is not maintained anymore, you can use Facebook's pyre2 packages and don't need to change any code. You can use the package:

pip install pyre2

Reference: https://github.com/facebook/pyre2

Alex
  • 21
  • 4