使用pip安装小工具snbextension时出错



我正在使用python 3.1和pip来安装这些包。在安装相同的程序时,我在为lxml和numpy构建轮子时出错。这是错误日志:

Collecting widgetsnbextension==3.4.2
Using cached widgetsnbextension-3.4.2-py2.py3-none-any.whl (2.2 MB)
Requirement already satisfied: setuptools>=18.5 in /home/sandeep/python_virtualenvs/projectkb/lib/python3.10/site-packages (from ipython==7.1.1->-r demo_requirementes.txt (line 9)) (45.0.0)
Building wheels for collected packages: lxml, numpy, pyzmq
Building wheel for lxml (setup.py) ...

src/lxml/etree.c:168998:3: note: in expansion of macro ‘__Pyx_TraceReturn’
168998 |   __Pyx_TraceReturn(__pyx_r, 0);
|   ^~~~~~~~~~~~~~~~~
src/lxml/etree.c: In function ‘__pyx_f_4lxml_5etree__countNsDefs’:
src/lxml/etree.c:5384:32: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘use_tracing’; did you mean ‘tracing’?
5384 |           if (unlikely(tstate->use_tracing) && !tstate->tracing &&
|                                ^~~~~~~~~~~
src/lxml/etree.c:888:43: note: in definition of macro ‘unlikely’
888 |   #define unlikely(x) __builtin_expect(!!(x), 0)
|                                           ^
src/lxml/etree.c:169020:3: note: in expansion of macro ‘__Pyx_TraceCall’
169020 |   __Pyx_TraceCall("_countNsDefs", __pyx_f[13], 382, 0, __PYX_ERR(13, 382, __pyx_L1_error));
|   ^~~~~~~~~~~~~~~
src/lxml/etree.c:5393:28: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘use_tracing’; did you mean ‘tracing’?
5393 |       if (unlikely(tstate->use_tracing) && !tstate->tracing &&
|                            ^~~~~~~~~~~
src/lxml/etree.c:888:43: note: in definition of macro ‘unlikely’
888 |   #define unlikely(x) __builtin_expect(!!(x), 0)
|                                           ^
src/lxml/etree.c:169020:3: note: in expansion of macro ‘__Pyx_TraceCall’
169020 |   __Pyx_TraceCall("_countNsDefs", __pyx_f[13], 382, 0, __PYX_ERR(13, 382, __pyx_L1_error));
|   ^~~~~~~~~~~~~~~
src/lxml/etree.c:5451:27: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘use_tracing’; did you mean ‘tracing’?
5451 |               if (tstate->use_tracing) {
|                           ^~~~~~~~~~~
src/lxml/etree.c:169101:3: note: in expansion of macro ‘__Pyx_TraceReturn’

Compile failed: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitmnx27mzb.c -o tmp/xmlXPathInitmnx27mzb.o
cc tmp/xmlXPathInitmnx27mzb.o -lxml2 -o a.out
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
Rolling back uninstall of lxml
Moving to /home/sandeep/python_virtualenvs/projectkb/lib/python3.10/site-packages/lxml-4.9.1.dist-info/
from /home/sandeep/python_virtualenvs/projectkb/lib/python3.10/site-packages/~xml-4.9.1.dist-info
Moving to /home/sandeep/python_virtualenvs/projectkb/lib/python3.10/site-packages/lxml/
from /home/sandeep/python_virtualenvs/projectkb/lib/python3.10/site-packages/~xml
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> lxml
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

注意:我甚至安装了lxml包,但这并没有帮助。

我能做些什么来解决这个问题?感谢

由于上述依赖项的安装工作正常,问题似乎是requirements.txt文件中提到了这些依赖项的旧版本。该错误可能是由于这些旧依赖项的版本与您当前的Python环境不兼容。

  • 解决此问题的一种方法是删除requirements.txt文件中的包版本,例如,如果我们有lxml==4.2,我们可以剥离该版本并在该文件中只保留lxml。其他依赖项也是如此。可以使用此正则表达式来剥离版本:
sed 's/==.*//' requirements.txt > requirements_new.txt
  • [可选]可以使用此处提到的pip尝试此--upgrade-strategy eager标志https://stackoverflow.com/a/55805167/3784226(尚未尝试(

  • 最后将更新后的版本存储到新的需求文件中:

pip freeze > requirements-new.txt

如果您面临与此相关的任何其他问题,请告诉我。

最新更新