python编辑器,安卓12版本,为什么安装docx,xml出错?

原代码

# 安卓12,为什么安装docx,xml出错
import subprocess
# 设置清华大学镜像源
subprocess.run(["pip", "config", "set", "global.index-url", "https://pypi.tuna.tsinghua.edu.cn/simple"])
# 安装依赖库
subprocess.run(["pip", "install", "lxml==4.6.3"])
subprocess.run(["pip", "install", "python-docx==0.8.11"])
# 导入所需库
from docx import Document
# 创建一个新的Word文档
doc = Document()
# 添加内容到文档
doc.add_heading('Hello, World!', level=1)
doc.add_paragraph('This is a sample document.')
# 保存文档
doc.save('output.docx')

运行机制出错

#这是python编辑器app
Writing to /data/user/0/coding.yu.pythoncompiler.new/files/home/.config/pip/pip.conf
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting lxml==4.6.3
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e5/21/a2e4517e3d216f0051687eea3d3317557bde68736f038a3b105ac3809247/lxml-4.6.3.tar.gz (3.2 MB)
     ━━━━━━━ 3.2/3.2 13.6     eta 0:00:00
             MB      MB/s
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      Building lxml version 4.6.3.
      Building without Cython.
      Error: Please make sure the libxml2 and libxslt development packages are installed.
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
a4f5bdbef24e0f905d351f34cf351ceb131f5cddf78/lxml-4.9.3.tar.gz (3.6 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      Building lxml version 4.9.3.
      Building without Cython.
      Error: Please make sure the libxml2 and libxslt development packages are installed.
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
Traceback (most recent call last):
  File "/data/user/0/coding.yu.pythoncompiler.new/files/default.py", line 11, in <module>
    from docx import Document
ModuleNotFoundError: No module named 'docx'
[Process completed (code 1) - press Enter]

中文翻译如下

抱歉给你带来了不便。根据错误信息显示,安装lxml库时出现了问题,需要确保安装了libxml2libxslt开发包。你可以尝试使用以下命令安装这些开发包:
bashsudo apt-get install libxml2-dev libxslt-dev安装完成后,再次运行代码,看是否能够成功安装所需的库。另外,还有一个错误提示是找不到docx模块,可能是因为没有正确安装该模块。你可以尝试使用以下命令安装python-docx库:bashpip install python-docx==0.8.11如果上述方法仍然无法解决问题,请提供更多详细信息,以便我进一步帮助你。谢谢!

添加问题解决方法
在这里插入图片描述
导入本地库

pip install /storage/emulated/0/下载/Download/python-docx-0.8.11.tar.gz

在这里插入图片描述

原出处

本来以为这个事又要等待好久,甚至3个月10年8年才能解决
(myenv) root@localhost:/home# (myenv) root@localhost:/home# pip install /storage/emulated/0/下载/Download/python-docx-0.8.11.tar.gzLooking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleProcessing /storage/emulated/0/下载/Download/python-docx-0.8.11.tar.gz Preparing metadata (setup.py) ... doneRequirement already satisfied: lxml>=2.3.2 in ./myenv/lib/python3.7/site-packages (from python-docx==0.8.11) (4.6.3)Building wheels for collected packages: python-docx Building wheel for python-docx (setup.py) ...done Created wheel for python-docx: filename=python_docx-0.8.11-py3-none-any.whl size=184489 sha256=54addc677f70b17e8c58d29283fc325d740e9a6843ca4085dfab0a2c613dc294 Stored in directory: /root/.cache/pip/wheels/cf/90/81/c706c39e5763039f7ac3ed464914c9aa081cfe0534e610647bSuccessfully built python-docxInstalling collected packages: python-docx Attempting uninstall: python-docx Found existing installation: python-docx 0.8.11 Uninstalling python-docx-0.8.11: Successfully uninstalled python-docx-0.8.11Successfully installed python-docx-0.8.11(myenv) root@localhost:/home#(myenv) root@localhost:/home# (myenv) root@localhost:/home#(myenv) root@localhost:/home#(myenv) root@localhost:/home# python Python 3.7.3 (default, Jun 29 2023, 18:03:57)[GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>>>>>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值