繁体   English   中英

无法运行 pytest,没有名为 readline 的模块

[英]Unable to run pytest, no module named readline

sh-4.2# python --version
Python 3.5.2

sh-4.2# pip --version
pip 9.0.1 from /usr/local/lib/python3.5/site-packages (python 3.5)

sh-4.2# pytest --version
pytest 6.1.0

sh-4.2# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

在我的项目上启动 pytest 时,我有以下堆栈跟踪:

sh-4.2# pytest
/usr/local/lib/python3.5/site-packages/addok/config/__init__.py:2: PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/addok/shell.py", line 23, in <module>
INTERNALERROR>     import gnureadline as readline  # For OSX.
INTERNALERROR> ImportError: No module named 'gnureadline'
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/_pytest/main.py", line 253, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/_pytest/config/__init__.py", line 982, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/hooks.py", line 308, in call_historic
INTERNALERROR>     res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/addok/pytest.py", line 27, in pytest_configure
INTERNALERROR>     addok_config.load()
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/addok/config/__init__.py", line 36, in load
INTERNALERROR>     self.load_core_plugins()
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/addok/config/__init__.py", line 68, in load_core_plugins
INTERNALERROR>     plugin = importlib.import_module(path)
INTERNALERROR>   File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module
INTERNALERROR>     return _bootstrap._gcd_import(name[level:], package, level)
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 171, in exec_module
INTERNALERROR>     exec(co, module.__dict__)
INTERNALERROR>   File "/usr/local/lib/python3.5/site-packages/addok/shell.py", line 25, in <module>
INTERNALERROR>     import readline  # Normal way.
INTERNALERROR> ImportError: No module named 'readline'

因此,我安装了 readline:

sh-4.2# pip install readline

这给出了以下错误:

  ============ Building the readline extension module ============

  running bdist_wheel
  running build
  running build_ext
  building 'readline' extension
  creating build
  creating build/temp.linux-x86_64-3.5
  creating build/temp.linux-x86_64-3.5/Modules
  creating build/temp.linux-x86_64-3.5/Modules/3.x
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/usr/local/include/python3.5m -c Modules/3.x/readline.c -o build/temp.linux-x86_64-3.5/Modules/3.x/readline.o -Wno-strict-prototypes
  Modules/3.x/readline.c: In function ‘PyInit_readline’:
  Modules/3.x/readline.c:1179:34: warning: assignment from incompatible pointer type [enabled by default]
       PyOS_ReadlineFunctionPointer = call_readline;
                                    ^
  creating build/lib.linux-x86_64-3.5
  gcc -pthread -shared build/temp.linux-x86_64-3.5/Modules/3.x/readline.o readline/libreadline.a readline/libhistory.a -L/usr/local/lib -lncurses -lpython3.5m -o build/lib.linux-x86_64-3.5/readline.cpython-35m-x86_64-linux-gnu.so
  /usr/bin/ld: cannot find -lncurses
  collect2: error: ld returned 1 exit status
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for readline
  Running setup.py clean for readline
Failed to build readline
Installing collected packages: readline
  Running setup.py install for readline ... error
    Complete output from command /usr/local/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-d484khsy/readline/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-0sdba9rg-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_ext
    building 'readline' extension
    creating build
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/Modules
    creating build/temp.linux-x86_64-3.5/Modules/3.x
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/usr/local/include/python3.5m -c Modules/3.x/readline.c -o build/temp.linux-x86_64-3.5/Modules/3.x/readline.o -Wno-strict-prototypes
    Modules/3.x/readline.c: In function ‘PyInit_readline’:
    Modules/3.x/readline.c:1179:34: warning: assignment from incompatible pointer type [enabled by default]
         PyOS_ReadlineFunctionPointer = call_readline;
                                      ^
    creating build/lib.linux-x86_64-3.5
    gcc -pthread -shared build/temp.linux-x86_64-3.5/Modules/3.x/readline.o readline/libreadline.a readline/libhistory.a -L/usr/local/lib -lncurses -lpython3.5m -o build/lib.linux-x86_64-3.5/readline.cpython-35m-x86_64-linux-gnu.so
    /usr/bin/ld: cannot find -lncurses
    collect2: error: ld returned 1 exit status
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/local/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-d484khsy/readline/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-0sdba9rg-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-d484khsy/readline/

我不知道如何解决。

如何修复上述错误以运行 pytest? 为了能够运行 pytest,它至少是正确的方向吗?

Moreover, this takes place in a docker container which image is https://hub.docker.com/layers/saagie/python/3.5.2-1.3.1-centos/images/sha256-6dc9637c93ae1ba0f5553707da1e97fe7c81c883b501e6717624f6e65f9d0f22?context=explore

为了能够获取 readline 模块并对其进行编译,编译器需要 ncurses 库。

该库可以通过以下方式下载:

yum update
yum install ncurses-devel

然后:

pip install readline

资源:

https://www.osetc.com/en/how-to-install-ncurse-library-in-ubuntu-debian-centos-fedora-linux.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM