我py2exe用来将我的程序与多个GUI转换为独立的可执行文件.我使用PyQt来创建GUI.我运行的主要脚本实例化主UI,其中包含可以打开子UI的按钮,选项卡等.主要的脚本是main_ui.py.
我按照教程如何使用py2exe,所以我有以下内容setup.py:
from distutils.core import setup
import py2exe
setup(windows=['main_ui.py'])
Run Code Online (Sandbox Code Playgroud)
然后,在CMD中:> python setup.py py2exe.
我尝试使用简单的脚本创建一个练习exe,一切正常.但是,当我尝试从中创建exe时出现错误main_ui.py.
这是输出:
L:\internal\(path)>python setup.py py2exe
running py2exe
creating L:\internal\(path)\build
creating L:\internal\(path)\build\bdist.win32
creating L:\internal\(path)\build\bdist.win32\winexe
creating L:\internal\(path)\build\bdist.win32\winexe\collect-2.7
creating L:\internal\(path)\build\bdist.win32\winexe\bundle-2.7
creating L:\internal\(path)\build\bdist.win32\winexe\temp
creating L:\internal\(path)\dist
*** searching for required modules ***
error: compiling 'C:\Python27\lib\site-packages\PyQt4\uic\port_v3\proxy_base.py' failed
SyntaxError: invalid syntax <proxy_base.py, line 26>
Run Code Online (Sandbox Code Playgroud)
这是proxy_base.py:
from PyQt4.uic.Compiler.proxy_metaclass import ProxyMetaclass
class ProxyBase(metaclass=ProxyMetaclass):
""" A base class for proxies using Python v3 …Run Code Online (Sandbox Code Playgroud) 我用来cgo调用动态库中的函数,其签名如下所示:
int decompress(int, const uint8_t *, size_t, uint8_t *, size_t);
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
// #include statements here
import "C"
import (
"unsafe"
)
func Decompress(comp_type int, data string, expected_size int) []byte {
compressedData := C.CString(data)
defer C.free(unsafe.Pointer(compressedData))
compressedDataSize := C.ulong(len(data))
decompressedData := C.malloc(C.ulong(C.sizeof_char * expected_size))
defer C.free(unsafe.Pointer(decompressedData))
decompressedDataSize := C.ulong(expected_size)
ret_val := C.XpressDecompress(C.int(comp_type),
(*C.uchar) (compressedData),
compressedDataSize,
(*C.uchar) (decompressedData),
&decompressedDataSize)
decompressed := C.GoBytes(decompressedData, C.int(decompressedDataSize))
return decompressed
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试构建时出现此错误:
cannot convert compressedData (type *_Ctype_char) to type *_Ctype_uchar
将输入字符串转换为 的最佳方法是什么const unsigned char* …
这就是问题所在:给定块数 n(3 到 200 之间),返回可以建造的不同楼梯的数量。每种类型的楼梯应包含 2 个或更多台阶。不允许有两个台阶处于相同高度 - 每个台阶必须低于前一个台阶。所有台阶必须至少包含一块砖块。台阶的高度被分类为组成该台阶的砖块的总数。
例如,当N = 3时,您只有1种选择如何建造楼梯,第一步的高度为2,第二步的高度为1:(#表示一块砖)
#
##
21
Run Code Online (Sandbox Code Playgroud)
当 N = 4 时,你仍然只有 1 个楼梯选择:
#
#
##
31
Run Code Online (Sandbox Code Playgroud)
但是当 N = 5 时,有两种方法可以用给定的砖块建造楼梯。两个楼梯的高度可以为 (4, 1) 或 (3, 2),如下所示:
#
#
#
##
41
#
##
##
32
Run Code Online (Sandbox Code Playgroud)
我在网上找到了解决方案,但是我不太直观地理解动态规划的解决方案。
public class Answer {
static int[][] p = new int[201][201];
public static void fillP() {
p[1][1] = 1;
p[2][2] = 1;
for (int w = 3; w < 201 ; w++) {
for (int …Run Code Online (Sandbox Code Playgroud) 我有一个带有继续按钮的QDialog窗口。继续按钮是默认按钮,因为每当我按下Enter键时,都会按下继续按钮。我发现了一些奇怪的事情:当我按Enter键三下时,继续按钮也按了三下。但是,当我第四次按下它时,整个窗口关闭。我在关闭窗口的继续按钮下面有一个取消按钮,但是我没有将取消按钮设置为默认按钮或其他任何按钮。
我想覆盖它,keyPressEvent以便每当我进入窗口时,输入按钮将始终连接到继续按钮。
这就是我现在所拥有的:
class ManualBalanceUI(QtGui.QWidget):
keyPressed = QtCore.pyqtSignal()
def __init__(self, cls):
super(QtGui.QWidget, self).__init__()
self.window = QtGui.QDialog(None, QtCore.Qt.WindowSystemMenuHint)
self.ui = uic.loadUi('ManualBalanceUI.ui', self.window)
self.keyPressed.connect(self.on_key)
def keyPressEvent(self, event):
super(ManualBalanceUI, self).keyPressEvent(event)
self.keyPressed.emit(event)
def on_key(self, event):
if event.key() == QtCore.Qt.Key_Enter and self.ui.continueButton.isEnabled():
self.proceed() # this is called whenever the continue button is pressed
elif event.key() == QtCore.Qt.Key_Q:
self.window.close() # a test I implemented to see if pressing 'Q' would close the window
def proceed(self):
...
...
Run Code Online (Sandbox Code Playgroud)
但是,这似乎现在没有做任何事情。按下“ Q”不会关闭窗口,而且我无法真正确定“ enter”键是否起作用。
我事先看过这个问题:PyQt Connect to …