当前位置:网站首页>论pyscript使用感想(实现office预览)
论pyscript使用感想(实现office预览)
2022-07-29 04:20:00 【beginner2021】
一,对pyscript的期望(实现office预览)
众所周知python有很多对office操作的库,而js在这方面相对薄弱,pyscript刚好可以在html中运行python代码,原本想的是使用pyscript运行python代码将word转为html刚好用pyscript命名空间js与python互通的特点用js将转换结果写入iframe标签中实现文件预览
二,动手尝试
一,尝试库mammoth
因为pyscript使用的是pyoided来实现python的运行效果目前只能运行python3.1.0
尝试如下代码
import mammoth
def wordToHtml(filename):
with open(filename+".docx", "rb") as docx_file:
result = mammoth.convert_to_html(docx_file)
with open(filename+".html", "w") as html_file:
html_file.write(result.value)
# 支持word中存在图片
wordToHtml('1')我提前在python3.1.0环境中测试过可以运行,如图

转换结果如下
然后我先从pypi下载一个mammoth tar.gz格式的包 然后解压尝试用以下代码打包为whl格式文件引入pyscript
python setup.py check
python setup.py sdist bdist_wheel || true
然后用以下代码引入whl包
<py-env>- './mammoth-1.4.19-none-any.whl'</py-env>结果运行报错
ValueError: Couldn't find a pure Python 3 wheel for 'cobble<0.2,>=0.1.3'.
You can use `micropip.install(..., keep_going=True)` to get a list of all packages
with missing wheels.然后可能是whl包的问题于是我去pypi官网下载whl包

用以下代码引入包
<py-env>- './mammoth-1.4.19-py2.py3-none-any.whl'</py-env>结果还是报相同的错误

真的崩溃了,报错原因是没有正确的wheel轮子,pyscript的github上也有关于此问题的帖子这个whl包我尝试用python3.1.0安装过可以使用
二,尝试pydocx
尝试运行python代码
from pydocx import PyDocX
html = PyDocX.to_html("test.docx")
f = open("test.html", 'w', encoding="utf-8")
f.write(html)
f.close()打包pydocx.tar.gz为pydocx.whl(官网下载tar.gz解压并进入)
python setup.py check
python setup.py sdist bdist_wheel || true然后以下代码引入
<py-env>- 'PyDocX-0.9.10-py3-none-any.whl'</py-env>然后引入成功了,但是运行报错了
三,总结
pyscript是一个新出的模块还是有很多的问题不建议新手尝试,他通过pyodied实现python运行效果
但是只能支持python3.1.0好多模块还都不支持,有兴趣的朋友可以自己尝试一下
相关资源链接:打包好的pydocx.whl文件
边栏推荐
- Multi card training in pytorch
- 如何查询版本的提交号
- Two forms of softmax cross entropy + numpy implementation
- The difference between dynamic, VaR and object in fluent
- 不会就坚持60天吧 神奇的字典
- Deploy Jenkins using containers
- Applet: Area scrolling, pull-down refresh, pull-up load more
- Don't insist on 66 days. Weight generates random numbers
- Shell string segmentation
- 不会就坚持70天吧 数组中第k大的数
猜你喜欢

Machine vision Series 2: vs DLL debugging

不会就坚持66天吧 权重生成随机数

Not for 63 days. The biggest XOR

Whole house WiFi solution: mesh router networking and ac+ap

Record of problems encountered in ROS learning

Class starts! See how smardaten decomposes complex business scenarios

14. Haproxy+kept load balancing and high availability

Don't stick to it for 68 days. Baboons eat bananas

Can you really write restful API?

Deep learning training strategy -- warming up the learning rate
随机推荐
opengauss预检查安装
Implementation of jump connection of RESNET (pytorch)
Beginner: array & String
Exception handling: pyemd or pyemd not found
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
C语言:浅谈各种复杂的声明
15.federation
Taobao product details interface (product details page data interface)
Openfeign asynchronous call problem
通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值
Pix2.4.8 from start to installation (2021.4.4)
Is there any way for Youxuan database to check the log volume that the primary cluster transmits to the standby cluster every day?
Common components of solder pad (2021.4.6)
SQL time fuzzy query datediff() function
"Weilai Cup" 2022 Niuke summer multi school training camp 2H
Shell string segmentation
Why do I delete the original record (OP d) and then add a new one in Kafka when I update MySQL data
11. Backup switch
Not for 61 days. The shortest word code
编译与链接