Comments (15)
概述
已重现该问题。重现方式:
- 从 PyStand release 页面下载 PyStand-py38-pyqt5-lite.7z(PyStand-py38-pyqt5.7z);
- 将其解压至
PyStand-py38-pyqt5-lite
文件夹下,并重命名该文件夹为测试 PyStand-py38-pyqt5-lite
; - 双击 PyStand.exe 启动,发现弹出如上错误对话框;
问题原因
路径中包含中文会导致无法找到 platform plugins。可以在 PyStand.int
开头加入如下代码:
# vim: set ts=4 sw=4 tw=0 et ft=python :
import sys, os
import os.path
from PyQt5.QtCore import *
os.MessageBox(QTextCodec.codecForLocale().name())
os.MessageBox('Qt5 Plugins path: {0}'.format(QLibraryInfo.location(QLibraryInfo.PluginsPath)))
你会发现,中文路径中的汉字经过 GBK 编码又被 Qt 以 Latin-1 解码:
>>> '测试'.encode('gbk').decode('latin_1')
'²âÊÔ'
经过测试,我发现两种有效的解决方案。这两种解决方案都是使用相对路径来绕过中文路径带来的问题。
解决方案一
# vim: set ts=4 sw=4 tw=0 et ft=python :
import sys, os
import os.path
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'.\site-packages\PyQt5\Qt5\plugins' #### 这一行是新增的。用的是相对路径。
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
app = QApplication([])
解决方案二
# vim: set ts=4 sw=4 tw=0 et ft=python :
import sys, os
import os.path
from PyQt5.QtCore import *
QCoreApplication.addLibraryPath(r'.\site-packages\PyQt5\Qt5\plugins') #### 这一行是新增的。用的是相对路径。
from PyQt5.QtWidgets import *
app = QApplication([])
from pystand.
不一定是中文路径会导致这个问题,我在 64 位 Win7 纯英文路径下也遇见这个问题。
同样的程序放在 32位 Win7 运行没有问题。
分别尝试以下两条语句后还是一样的报错情况(试了绝对路径和相对路径,还试了以管理员身份运行)
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'.\site-packages\PyQt5\Qt5\plugins'
QCoreApplication.addLibraryPath(r'.\site-packages\PyQt5\Qt5\plugins')
from pystand.
这恐怕是 Qt 的限制吧,不是 PyStand 的锅,或者可以在 PyStand.int 里先检测下,如果中文路径就把 Qt 库拷贝到其它地方,并加入 sys.path
from pystand.
或者换成 PySide 试试?用那个 QtPy 的包做兼容
from pystand.
但是好像别的打包工具出来完全没有这个问题啊,比如nutika
from pystand.
或者换成 PySide 试试?用那个 QtPy 的包做兼容
好主意,我改天试试pyside2
from pystand.
@qyw233 因为 nutika 或者 PyInstaller 每次运行都要把所有文件解压到一个临时目录(英文路径)再运行,所以没有这个问题:
问题是你确定要 PyInstaller/nutika 这种又慢又臃肿的打包方式么?你就是 ssd 够快,每次运行解压出几十个文件来,然后让 Windows Defender 全部扫描一次才能真正开始。
想想都头大,你即便开头检测发现中文路径,然后自己拷贝一下 Qt 的动态库,也只是仅仅碰到中文路径的时候需要拷贝,并且是第一次运行的时候需要拷贝,后面就复用了,根本用不着跟 PyInstaller/nutika 那种不管什么情况,每次解压,运行完又删除的策略一样。
from pystand.
概述
已重现该问题。重现方式:
- 从 PyStand release 页面下载 PyStand-py38-pyqt5-lite.7z(PyStand-py38-pyqt5.7z);
- 将其解压至
PyStand-py38-pyqt5-lite
文件夹下,并重命名该文件夹为测试 PyStand-py38-pyqt5-lite
;- 双击 PyStand.exe 启动,发现弹出如上错误对话框;
问题原因
路径中包含中文会导致无法找到 platform plugins。可以在
PyStand.int
开头加入如下代码:# vim: set ts=4 sw=4 tw=0 et ft=python : import sys, os import os.path from PyQt5.QtCore import * os.MessageBox(QTextCodec.codecForLocale().name()) os.MessageBox('Qt5 Plugins path: {0}'.format(QLibraryInfo.location(QLibraryInfo.PluginsPath)))你会发现,中文路径中的汉字经过 GBK 编码又被 Qt 以 Latin-1 解码:
>>> '测试'.encode('gbk').decode('latin_1') '²âÊÔ'
经过测试,我发现两种有效的解决方案。这两种解决方案都是使用相对路径来绕过中文路径带来的问题。
解决方案一
# vim: set ts=4 sw=4 tw=0 et ft=python : import sys, os import os.path os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'.\site-packages\PyQt5\Qt5\plugins' #### 这一行是新增的。用的是相对路径。 from PyQt5.QtCore import * from PyQt5.QtWidgets import * app = QApplication([])解决方案二
# vim: set ts=4 sw=4 tw=0 et ft=python : import sys, os import os.path from PyQt5.QtCore import * QCoreApplication.addLibraryPath(r'.\site-packages\PyQt5\Qt5\plugins') #### 这一行是新增的。用的是相对路径。 from PyQt5.QtWidgets import * app = QApplication([])
非常感谢你!
from pystand.
帅.
你可以用直接路径,从 PyStand 里面取出 __file__
来:
HOME = os.path.dirname(os.path.abspath(__file__))
from pystand.
感谢各位大佬,不过还有一点问题,就是使用QtWebEngine的时候上述方法还是不太可以,甚至连错误都没有报,不知道为啥
from pystand.
最新的 PyQt5 已经不包含 QtWebEngine 了,你要单独安装
pip install PyQtWebEngine
然后把以来 dll/pyd 还有 sip 文件拷贝过去。
from pystand.
我已经把包括那个PyQtWebEngine全部拷贝过去了,在英文路径的时候一切正常,但是就是不能运行在中文路径,甚至在解决上面那个plugins问题之后没有报错程序就关闭了
from pystand.
实在不行,那你就在 pystand.int 里面检测下中文路径,然后把 dll/pyd 拷贝到某个地方,设置 sys.path 再 import 呗
from pystand.
主要是他连错误都不报,不知道要拷贝啥,如果是用pyinstall打包的exe他会报错找不到啥把相应文件拷到和exe的同一目录就可以。但是同样的文件拷贝在这里还是不行并且不报任何错
from pystand.
CMake的时候,出这个问题CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage,请问各位大佬怎么解决啊
from pystand.
Related Issues (20)
- win7无法启动python的一些经验、报错展示 HOT 1
- 导入ddddocr报错 HOT 3
- 加入numpy包的时候出现错误 HOT 9
- numpy导入问题补录 HOT 2
- 将runtime换成python3.10版本无法运行 HOT 5
- 360报毒了 HOT 1
- 请教:将python的stdout重定向到文件 HOT 3
- 请教一下如何精简pyqt HOT 2
- 如何解决multiprocessing导入时无限开启进程? HOT 3
- 如何打包ffmpeg HOT 1
- 加密问题:始终识别不到模块 HOT 5
- 建议在内置初始化脚本帮忙初始化DLL加载目录 HOT 4
- 是否可以内嵌 int 代码编译或者支持 __main__.py HOT 2
- 编译器问题
- PyStand启动速度 HOT 3
- 在脚本中启动新进程运行python
- 可以自己加入pip吗 HOT 3
- 64位启动脚本命名问题:不支持中文? HOT 3
- WinRar 制作自解压程序在 win7 解压运行时找不到 Py_Main HOT 2
- 导入numpy报错,可能是python小版本对不上的问题
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pystand.