我一直在使用cx_Freeze一段时间,我有一件事我真的想做:将所有文件放入一个我可以分发的可执行文件中.发送一个包含30个文件的文件夹并不是真的用户友好,所有文件都在同一个目录中.我怎么能做到这一点?谢谢.
我正在使用请求库在python 3.3中构建一个应用程序.当我尝试获取具有SSL连接的URL时,我想使用verify = true验证它.这在运行我的python脚本时非常有效.
当我冻结相同的脚本时,它会崩溃.它错过了一些东西,我真的无法弄清楚如何将它集成到我的冻结应用程序中.
我收到以下错误(这也会触发其他错误,但我不在这里发布):
Traceback (most recent call last):
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 422, in urlopen
body=body, headers=headers)
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 274, in _make_request
conn.request(method, url, **httplib_request_kw)
File "C:\Python33-32\lib\http\client.py", line 1049, in request
self._send_request(method, url, body, headers)
File "C:\Python33-32\lib\http\client.py", line 1087, in _send_request
self.endheaders(body)
File "C:\Python33-32\lib\http\client.py", line 1045, in endheaders
self._send_output(message_body)
File "C:\Python33-32\lib\http\client.py", line 890, in _send_output
self.send(msg)
File "C:\Python33-32\lib\http\client.py", line 828, in send
self.connect()
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 105, in connect
ssl_version=self.ssl_version)
File "C:\Python33-32\lib\site-packages\requests\packages\urllib3\util.py", line 281, in ssl_wrap_socket
context.load_verify_locations(ca_certs) …
Run Code Online (Sandbox Code Playgroud) 我目前正在运行Windows 7 Home 64位,我正在开发一个程序,我想为32位和64位Windows操作系统提供这些程序.当我使用cx_Freeze将.py转换为.exe时,它只允许将其安装在64位操作系统上.
我是否需要购买一台32位计算机才能将其转换为32位程序,或者是否有一组特殊的命令可用于使cx_freeze同时创建x32和x64 exe?
from cx_Freeze import *
import sys
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [Executable("iNTMI.py", shortcutName = "iNTMI", shortcutDir = "DesktopFolder", base = base, icon = "C:/Program Files/iNTMI/assets/images/programIcon.ico")]
setup(
name = "iNTMI",
options = {"build_exe": {"packages": ["tkinter", "minecraftItems", "ProgFunctions", "minecraftItems"], "include_files": ["ProgFunctions.py", "minecraftItems.py"]}},
executables = executables
)
Run Code Online (Sandbox Code Playgroud) 我几天来一直在处理这个问题,希望得到一些帮助.我开发了一个带有导入模块的GUI应用程序tkinter,numpy,scipy,matplotlib,它在python本身运行良好.转换为*.exe后,一切都按预期工作,但不是matplotlib部分.当我按下我定义的情节按钮时,*.exe只会关闭并且不显示任何情节.所以我想做一个简约的例子,我简单地绘制一个sin函数并且我面临同样的问题:在python中完美工作,当将它转换为*.exe时,它在按下情节按钮时崩溃.简约的例子在这里:
import tkinter as tk
import matplotlib.pyplot as plt
import numpy as np
class MainWindow(tk.Frame):
def __init__(self):
tk.Frame.__init__(self,bg='#9C9C9C',relief="flat", bd=10)
self.place(width=x,height=y)
self.create_widgets()
def function(self):
datax = np.arange(-50,50,0.1)
datay = np.sin(datax)
plt.plot(datax,datay)
plt.show()
def create_widgets(self):
plot = tk.Button(self, text='PLOT', command=self.function)
plot.pack()
x,y=120,300
root=tk.Tk()
root.geometry(str(x)+"x"+str(y))
app = MainWindow()
app.mainloop()
Run Code Online (Sandbox Code Playgroud)
并查看我的相应"setup.py"以使用cx_freeze进行转换.
import cx_Freeze
import matplotlib
import sys
import numpy
import tkinter
base = None
if sys.platform == "win32":
base = "Win32GUI"
executables = [cx_Freeze.Executable("test.py", base=base)]
build_exe_options = {"includes": ["matplotlib.backends.backend_tkagg","matplotlib.pyplot",
"tkinter.filedialog","numpy"],
"include_files":[(matplotlib.get_data_path(), "mpl-data")],
"excludes":[],
} …
Run Code Online (Sandbox Code Playgroud) 我只是想知道是否可以更改cx_freeze脚本的程序图标,我环顾四周但我找不到任何东西.
我试图将.py脚本转换为.exe
cx_Freeze成功编译了exe.但是,当我运行exe文件时,它会抛出此错误:
ImportError:'appdirs'包是必需的; 通常,这与此软件包捆绑在一起,因此如果您收到此警告,请咨询您的分发包装商
这是我的setup.py
from cx_Freeze import setup, Executable
setup(
name = "dbx_sharelink" ,
version = "0.1" ,
description = " " ,
executables = [Executable("dbx_sharelink.py")] ,
)
Run Code Online (Sandbox Code Playgroud)
源代码Python脚本
import sys
import dropbox
import pandas as pd
import sys
import os
dbx = dropbox.Dropbox('xxxxxxxxxxxxxxxxx')
def getSharedLink(full_path):
try:
link = dbx.sharing_create_shared_link(full_path).url
except dropbox.exceptions.ApiError as err:
print('*** API error', err)
return None
return link
print(sys.argv[1])
link = getSharedLink("/A_DATA/data")
df = pd.DataFrame([{'link':link}])
df.to_clipboard(index=False,header=False)
os.system("pause")
Run Code Online (Sandbox Code Playgroud)
如何解决此错误?
我正在尝试安装cx_freeze和scipy,但每次都出现编译失败,错误代码为1错误.这是我在尝试使用cx-freeze时所看到的内容:
error: file 'C:\Users\myAccount\AppData\Local\Temp\pip-install-nabp1tpo\cx-fre
eze\cxfreeze-postinstall' does not exist
----------------------------------------
Command "c:\users\myAccount\appdata\local\programs\python\python37\python.exe -u -
c "import setuptools, tokenize;__file__='C:\\Users\\myAccount\\AppData\\Local\\Tem
p\\pip-install-nabp1tpo\\cx-freeze\\setup.py';f=getattr(tokenize, 'open', open)(
__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __fil
e__, 'exec'))" install --record C:\Users\myAccount\AppData\Local\Temp\pip-record-3
6fbtmht\install-record.txt --single-version-externally-managed --compile" failed
with error code 1 in C:\Users\myAccount\AppData\Local\Temp\pip-install-nabp1tpo\c
x-freeze\
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
为什么“\”和“/”混用?
os.getcwd()
发出反斜杠字符串。
另一方面,QFileDialog
发出正斜杠字符串。
为什么?
例子
请执行此示例代码。
from PySide import QtGui
from PySide import QtCore
import sys
import os
class DirectoryPrinter(QtGui.QWidget):
def __init__(self,parent=None):
super(DirectoryPrinter,self).__init__(parent=None)
self.filedialog_pushbutton = QtGui.QPushButton("filedialog",self)
self.connect(self.filedialog_pushbutton,QtCore.SIGNAL("clicked()"),self.filename_getter)
def filename_getter(self):
print("from os.getcwd()",os.getcwd())
filename = QtGui.QFileDialog.getOpenFileName(self,"Select your file",os.path.expanduser("~"))[0]
print("from QFileDialog",filename)
def main():
try:
QtGui.QApplication([])
except Exception as e:
print(22,e)
directoryprinter = DirectoryPrinter()
directoryprinter.show()
sys.exit(QtGui.QApplication.exec_())
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
结果(在我的场合)
来自os.getcwd()
:J:\
来自QFileDialog
:C:/Users/******/setup.py
以前我问过一个类似的问题:cx_Freeze无法找到mkl:MKL FATAL ERROR:无法加载mkl_intel_thread.dll
但现在我有一个微妙的区别。我想在不安装 anaconda 的情况下运行程序,只是在cmd.exe
终端内,但似乎我做错了什么或者这是不可能的。
python setup.py bdist_msi
使用 using生成我的应用程序后cx-freeze
,我可以在 anaconda 环境中安装然后运行它,但是如果我只是打开一个cmd.exe
终端并运行它,我会得到
INTEL MKL ERROR: The specified module could not be found. mkl_intel_thread.dll.
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Run Code Online (Sandbox Code Playgroud)
但是,运行时
where mkl_intel_thread.dll
Run Code Online (Sandbox Code Playgroud)
dll找到了,所以我认为这意味着它已在系统中注册(我更习惯使用Linux,所以可能是我错了)。
我怎么能解决这个问题?
我有一个 python 类,它有几个属性。我想实现一个方法,它将返回一些属性作为字典。我想用装饰器标记属性。这是一个例子:
class Foo:
@export_to_dict # I want to add this property to dict
@property
def bar1(self):
return 1
@property # I don't want to add this propetry to dict
def bar2(self):
return {"smth": 2}
@export_to_dict # I want to add this property to dict
@property
def bar3(self):
return "a"
@property
def bar4(self):
return [2, 3, 4]
def to_dict(self):
return ... # expected result: {"bar1": 1, "bar3": "a"}
Run Code Online (Sandbox Code Playgroud)
实现它的一种方法是使用export_to_dict装饰器为属性设置一个附加属性,如下所示:
def export_to_dict(func):
setattr(func, '_export_to_dict', True)
return func
Run Code Online (Sandbox Code Playgroud)
并通过调用_export_to_dict
时的属性来搜索属性。 …
python ×9
cx-freeze ×8
python-3.x ×3
32-bit ×1
64-bit ×1
decorator ×1
dll ×1
icons ×1
intel-mkl ×1
matplotlib ×1
properties ×1
pyside ×1
qfiledialog ×1
tkinter ×1
windows-10 ×1