【问题标题】:Installing Python's new regex module not working安装 Python 的新正则表达式模块不起作用
【发布时间】:2016-04-20 07:16:25
【问题描述】:

我正在尝试安装 alternative regular expression module 来替换 re,但安装模块时遇到困难。我已经访问过这个stack overflow question,当按照 Pavan 的说明进行操作时,终端(我正在运行 OSX El Capitan)会产生以下输出:

编辑:澄清一下,此输出是在发出命令 pip install regex 时产生的。

Collecting regex
  Using cached regex-2016.04.15.tar.gz
Installing collected packages: regex
  Running setup.py install for regex ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/z6/vncx8j5977xd96vnrtj41xt40000gn/T/pip-build-AwqJ7Z/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/z6/vncx8j5977xd96vnrtj41xt40000gn/T/pip-uG2qOh-record/install-record.txt --single-version-externally-managed --compile:
    /Library/Python/2.7/site-packages/setuptools-20.9.0-py2.7.egg/setuptools/dist.py:285: UserWarning: Normalizing '2016.04.15' to '2016.4.15'
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.11-intel-2.7
    copying Python2/regex.py -> build/lib.macosx-10.11-intel-2.7
    copying Python2/_regex_core.py -> build/lib.macosx-10.11-intel-2.7
    copying Python2/test_regex.py -> build/lib.macosx-10.11-intel-2.7
    running build_ext
    building '_regex' extension
    creating build/temp.macosx-10.11-intel-2.7
    creating build/temp.macosx-10.11-intel-2.7/Python2
    cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c Python2/_regex.c -o build/temp.macosx-10.11-intel-2.7/Python2/_regex.o
    Python2/_regex.c:16531:77: warning: '&&' within '||' [-Wlogical-op-parentheses]
                                if (state->total_errors < error_limit || i == 0 &&
                                                                      ~~ ~~~~~~~^~
    Python2/_regex.c:16531:77: note: place parentheses around the '&&' expression to silence this warning
                                if (state->total_errors < error_limit || i == 0 &&
                                                                                ^
    Python2/_regex.c:16534:38: warning: variable 'better' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                                else if (state->total_errors == error_limit)
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Python2/_regex.c:16542:33: note: uninitialized use occurs here
                                if (better) {
                                    ^~~~~~
    Python2/_regex.c:16534:34: note: remove the 'if' if its condition is always true
                                else if (state->total_errors == error_limit)
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Python2/_regex.c:16529:40: note: initialize the variable 'better' to silence this warning
                                BOOL better;
                                           ^
                                            = '\0'
    Python2/_regex.c:18564:28: warning: unused function 'match_get_group_dict' [-Wunused-function]
    Py_LOCAL_INLINE(PyObject*) match_get_group_dict(MatchObject* self) {
                               ^
    3 warnings generated.
    Python2/_regex.c:16531:77: warning: '&&' within '||' [-Wlogical-op-parentheses]
                                if (state->total_errors < error_limit || i == 0 &&
                                                                      ~~ ~~~~~~~^~
    Python2/_regex.c:16531:77: note: place parentheses around the '&&' expression to silence this warning
                                if (state->total_errors < error_limit || i == 0 &&
                                                                                ^
    Python2/_regex.c:16534:38: warning: variable 'better' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                                else if (state->total_errors == error_limit)
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Python2/_regex.c:16542:33: note: uninitialized use occurs here
                                if (better) {
                                    ^~~~~~
    Python2/_regex.c:16534:34: note: remove the 'if' if its condition is always true
                                else if (state->total_errors == error_limit)
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Python2/_regex.c:16529:40: note: initialize the variable 'better' to silence this warning
                                BOOL better;
                                           ^
                                            = '\0'
    Python2/_regex.c:18564:28: warning: unused function 'match_get_group_dict' [-Wunused-function]
    Py_LOCAL_INLINE(PyObject*) match_get_group_dict(MatchObject* self) {
                               ^
    3 warnings generated.
    cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c Python2/_regex_unicode.c -o build/temp.macosx-10.11-intel-2.7/Python2/_regex_unicode.o
    cc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -Wl,-F. build/temp.macosx-10.11-intel-2.7/Python2/_regex.o build/temp.macosx-10.11-intel-2.7/Python2/_regex_unicode.o -o build/lib.macosx-10.11-intel-2.7/_regex.so
    running install_lib
    copying build/lib.macosx-10.11-intel-2.7/_regex.so -> /Library/Python/2.7/site-packages
    error: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/_regex.so'

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/z6/vncx8j5977xd96vnrtj41xt40000gn/T/pip-build-AwqJ7Z/regex/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/z6/vncx8j5977xd96vnrtj41xt40000gn/T/pip-uG2qOh-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/z6/vncx8j5977xd96vnrtj41xt40000gn/T/pip-build-AwqJ7Z/regex/

看起来 C 编译器脾气暴躁并发脾气,非常感谢任何帮助。

【问题讨论】:

  • 您是否使用sudo 运行?因为这对我来说看起来像是权限错误......试试sudo pip install regex
  • 干杯,我自己应该想到这一点,但被我的终端喷出的 C 吓到了。 :)

标签: python regex


【解决方案1】:

这不是编译问题。您正在以没有足够权限的用户身份执行pip

Permission denied: '/Library/Python/2.7/site-packages/_regex.so'

以root身份运行:

$ sudo pip install regex

【讨论】:

  • 谢谢,回答我的问题。
  • 请不要在 SUDO 许可下运行 PIP,而是使用 --user
猜你喜欢
  • 2013-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-31
  • 2013-09-08
  • 1970-01-01
  • 2019-02-22
  • 2023-02-07
相关资源
最近更新 更多