skywind3000 / skywind3000/PyStand

将代码使用egg加密后 如何才能正确的读取egg文件内的文件

Open
#24 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.2k
Forks
146
PR merge metrics
No merged PRs in 30d

Description

在我的项目中 打包时候出现了错误 下面这行代码报错:

file = os.path.join("UI","Custom_UI","QToolTip.qss")
with open(file,'r') as f:
    self.setStyleSheet(f.read())

这里的qss文件是一个需要被读取的文件 用来设置UI样式

压缩成egg后 运行报错:

C:\Users\xyj\Desktop\3.0.0-alpha>Traceback (most recent call last):
Traceback (most recent call last):
  File "<string>", line 34, in <module>
  File "C:\Users\xyj\Desktop\3.0.0-alpha\MOS.int", line 13, in <module>
    Run()
  File "C:\Users\xyj\Desktop\3.0.0-alpha\script\Code\MainWindow.py", line 544, in Run
    ui = RunUi()
  File "C:\Users\xyj\Desktop\3.0.0-alpha\script\Code\MainWindow.py", line 58, in __init__
    self.__init__setToolTipDuration()
  File "C:\Users\xyj\Desktop\3.0.0-alpha\script\Code\MainWindow.py", line 498, in __init__setToolTipDuration
    self._toolTip = ToolTip(parent=self)
  File "C:\Users\xyj\Desktop\3.0.0-alpha\script\UI\Custom_UI\QToolTip.py", line 44, in __init__
    self.__setQss()
  File "C:\Users\xyj\Desktop\3.0.0-alpha\script\UI\Custom_UI\QToolTip.py", line 66, in __setQss
    with open(file,'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'UI\\Custom_UI\\QToolTip.qss'

之后我只好更改了代码 将需要被读取的内容改成一个py文件 并且内建一个函数 调用之后 就返回这个文件的内容 虽然这么可以解决这个问题 但是我并不想这么解决 (因为这个方法很不好 而且以后想快速的改这个qss列表 也很麻烦

改正前:
https://github.com/xianyongjian080402/Minecraft-Optimal-Starter_3/tree/b068e9e212fe5cf668a50d4c83523f7510749c5f

改正后:
https://github.com/xianyongjian080402/Minecraft-Optimal-Starter_3/tree/8629cf3f5d694ca0ba9eb55a28e1c94776f8b735

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with script/UI/Custom_UI/QToolTip.py and the referenced QToolTip.qss, then inspect how PyStand packages and exposes files inside an egg. Reproduce the FileNotFoundError using the packaged project and verify that the QSS resource can be read after packaging without converting it into a Python module.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.