lxml fails to import, with error `symbol not found in flat namespace '_xsltDocDefaultLoader'`

huangapple go评论55阅读模式
英文:

lxml fails to import, with error `symbol not found in flat namespace '_xsltDocDefaultLoader'`

问题

With the code:

from lxml.etree import HTML, XML

I get the traceback:

Traceback (most recent call last):
  File "/Users/username/code/project/lxml-test.py", line 3, in <module>
    from lxml.etree import HTML, XML
ImportError: dlopen(/Users/username/.virtualenvs/project-venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): 
symbol not found in flat namespace '_xsltDocDefaultLoader'

I'm on a mac m1 chip.

I installed libxml2 and libxslt via brew.

I'm running python 3.11 inside of a virtualenv.

What I've tried:

  • Uninstalling and re-installing lxml with pip, and tried several different versions. (4.7.1 & 4.8.0 didn't compile. All of the 4.9.0,1,2 versions give me the above error)
  • Installing libxml2 and libxslt via brew and then reinstalling python-lxml.
  • Installing python-lxml via conda (as suggested here)

EDIT:

I posted this bug in lxml's bug report forum, and was notified that this is a highly-duplicated bug report of Missing wheel for macos with M1 Edit.

英文:

With the code:

from lxml.etree import HTML, XML

I get the traceback:

Traceback (most recent call last):
  File &quot;/Users/username/code/project/lxml-test.py&quot;, line 3, in &lt;module&gt;
    from lxml.etree import HTML, XML
ImportError: dlopen(/Users/username/.virtualenvs/project-venv/lib/python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): 
symbol not found in flat namespace &#39;_xsltDocDefaultLoader&#39;

I'm on a mac m1 chip.

I installed libxml2 and libxslt via brew.

I'm running python 3.11 inside of a virtualenv.

What I've tried:

  • Uninstalling and re-installing lxml with pip, and tried several different versions. (4.7.1 & 4.8.0 didn't compile. All of the 4.9.0,1,2 versions give me the above error)
  • Installing libxml2 and libxslt via brew and then reinstalling python-lxml.
  • Installing python-lxml via conda (as suggested here)

EDIT:

I posted this bug in lxml's bug report forum, and was notified that this is a highly-duplicated bug report of Missing wheel for macos with M1 Edit

答案1

得分: 1

我最近在尝试在装有M1 Pro芯片的笔记本上的3.9虚拟环境中安装python-docx模块时遇到了类似的问题。

这个答案帮助我解决了我的问题:https://stackoverflow.com/questions/54127779/unable-to-install-python-docx-macos

基本上,你需要先使用pip在你的虚拟环境中安装setuptools,然后再尝试使用pip安装lxml:

pip install -U setuptools

希望这有所帮助。

英文:

I ran into a similar issue recently while trying to install the python-docx module within a 3.9 virtualenv on my laptop with the M1 Pro chip.

This answer helped solve my issue: https://stackoverflow.com/questions/54127779/unable-to-install-python-docx-macos

Basically, you'd need to install the setuptools with pip within your virtualenv first and then try to install lxml with pip:

pip install -U setuptools

I hope this helps.

答案2

得分: 1

我通过克隆lxml、构建它,并通过以下方式安装解决了我的问题:

pip install -e /path/to/lxml
英文:

I solved my problem by cloning lxml, building it, and installing it via

pip install -e /path/to/lxml

huangapple
  • 本文由 发表于 2023年2月14日 09:26:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442675.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定