当前位置:网站首页>论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
- Implementation of jump connection of RESNET (pytorch)
- Shell string segmentation
- Multi rotor six axis hardware selection
- Beginner: array & String
- 9. Delay queue
- The function "postgis_version" cannot be found when installing PostGIS
- 对一个元素使用多种变形的方法
- 不会就坚持64天吧 查找插入位置
- Pix2.4.8 from start to installation (2021.4.4)
猜你喜欢

10. Fallback message

UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)

通过js来实现一元二次方程的效果,输入a,b,c系数后可计算出x1和x2的值

不会就坚持68天吧 狒狒吃香蕉

How to solve the problem of store ranking?

It won't last for 65 days. It only appears once

No, just stick to it for 64 days. Find the insertion location

Machine vision Series 2: vs DLL debugging

Locally call tensorboard and Jupiter notebook on the server (using mobaxterm)

The principle of inverse Fourier transform (IFFT) in signal processing
随机推荐
Pytoch automatic mixing accuracy (AMP) training
Machine vision series 3:vs2019 opencv environment configuration
Don't stick to it for 68 days. Baboons eat bananas
Implementation of jump connection of RESNET (pytorch)
恒星科通邀您“湘”约第24届中国高速公路信息化大会暨技术产品展示会
No, just stick to it for 59 days
Record of problems encountered in ROS learning
索引的最左前缀原理
信号处理中的反傅里叶变换(IFFT)原理
Kotlin's list, map, set and other collection classes do not specify types
9.延迟队列
Do you have a boss to help me check whether the parameter configuration of the Flink SQL connection Kafka authentication Kerberos is wrong
不会就坚持63天吧 最大的异或
openFeign异步调用问题
数据库SQL语句实现数据分解的函数查询
No, just stick to it for 64 days. Find the insertion location
MPU6050
SVG--loading动画
异常处理:pyemd或PyEMD找不到
全屋WiFi方案:Mesh路由器组网和AC+AP