Giter Site home page Giter Site logo

Comments (15)

myd7349 avatar myd7349 commented on August 24, 2024 9
概述

已重现该问题。重现方式:

  • 从 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.

simpleowen avatar simpleowen commented on August 24, 2024 1

不一定是中文路径会导致这个问题,我在 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.

skywind3000 avatar skywind3000 commented on August 24, 2024

这恐怕是 Qt 的限制吧,不是 PyStand 的锅,或者可以在 PyStand.int 里先检测下,如果中文路径就把 Qt 库拷贝到其它地方,并加入 sys.path

from pystand.

skywind3000 avatar skywind3000 commented on August 24, 2024

或者换成 PySide 试试?用那个 QtPy 的包做兼容

from pystand.

qyw233 avatar qyw233 commented on August 24, 2024

但是好像别的打包工具出来完全没有这个问题啊,比如nutika

from pystand.

alayamanas avatar alayamanas commented on August 24, 2024

或者换成 PySide 试试?用那个 QtPy 的包做兼容

好主意,我改天试试pyside2

from pystand.

skywind3000 avatar skywind3000 commented on August 24, 2024

@qyw233 因为 nutika 或者 PyInstaller 每次运行都要把所有文件解压到一个临时目录(英文路径)再运行,所以没有这个问题:

问题是你确定要 PyInstaller/nutika 这种又慢又臃肿的打包方式么?你就是 ssd 够快,每次运行解压出几十个文件来,然后让 Windows Defender 全部扫描一次才能真正开始。

想想都头大,你即便开头检测发现中文路径,然后自己拷贝一下 Qt 的动态库,也只是仅仅碰到中文路径的时候需要拷贝,并且是第一次运行的时候需要拷贝,后面就复用了,根本用不着跟 PyInstaller/nutika 那种不管什么情况,每次解压,运行完又删除的策略一样。

from pystand.

alayamanas avatar alayamanas commented on August 24, 2024
概述

已重现该问题。重现方式:

  • 从 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.

skywind3000 avatar skywind3000 commented on August 24, 2024

帅.

你可以用直接路径,从 PyStand 里面取出 __file__ 来:

HOME = os.path.dirname(os.path.abspath(__file__))

from pystand.

qyw233 avatar qyw233 commented on August 24, 2024

感谢各位大佬,不过还有一点问题,就是使用QtWebEngine的时候上述方法还是不太可以,甚至连错误都没有报,不知道为啥

from pystand.

skywind3000 avatar skywind3000 commented on August 24, 2024

最新的 PyQt5 已经不包含 QtWebEngine 了,你要单独安装

pip install PyQtWebEngine

然后把以来 dll/pyd 还有 sip 文件拷贝过去。

from pystand.

qyw233 avatar qyw233 commented on August 24, 2024

我已经把包括那个PyQtWebEngine全部拷贝过去了,在英文路径的时候一切正常,但是就是不能运行在中文路径,甚至在解决上面那个plugins问题之后没有报错程序就关闭了

from pystand.

skywind3000 avatar skywind3000 commented on August 24, 2024

实在不行,那你就在 pystand.int 里面检测下中文路径,然后把 dll/pyd 拷贝到某个地方,设置 sys.path 再 import 呗

from pystand.

qyw233 avatar qyw233 commented on August 24, 2024

主要是他连错误都不报,不知道要拷贝啥,如果是用pyinstall打包的exe他会报错找不到啥把相应文件拷到和exe的同一目录就可以。但是同样的文件拷贝在这里还是不行并且不报任何错

from pystand.

balllei avatar balllei commented on August 24, 2024

CMake的时候,出这个问题CMake Error: CMAKE_RC_COMPILER not set, after EnableLanguage,请问各位大佬怎么解决啊

from pystand.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.