我有一个开源python软件(GridCal),它有一个用PyQt5制作的GUI.该程序是可以安装的pip3 install GridCal
.
我想知道我有什么必须这样做,当有人pip-install我的程序时,它出现在系统菜单上,就像安装Spyder(python IDE)时一样
到目前为止,我所能提供的只是setup.py
我的程序,但我不知道它是否相关.
from distutils.core import setup
import sys
import os
name = "GridCal"
# Python 2.4 or later needed
if sys.version_info < (3, 5, 0, 'final', 0):
raise (SystemExit, 'Python 3.5 or later is required!')
# Build a list of all project modules
packages = []
for dirname, dirnames, filenames in os.walk(name):
if '__init__.py' in filenames:
packages.append(dirname.replace('/', '.'))
package_dir = {name: name}
# Data_files (e.g. doc) …
Run Code Online (Sandbox Code Playgroud) 我对PyQt很新,我正在努力填充QTableView控件.
我的代码如下:
def data_frame_to_ui(self, data_frame):
"""
Displays a pandas data frame into the GUI
"""
list_model = QtGui.QStandardItemModel()
i = 0
for val in data_frame.columns:
# for the list model
if i > 0:
item = QtGui.QStandardItem(val)
#item.setCheckable(True)
item.setEditable(False)
list_model.appendRow(item)
i += 1
self.ui.profilesListView.setModel(list_model)
# for the table model
table_model = QtGui.QStandardItemModel()
# set table headers
table_model.setColumnCount(data_frame.columns.size)
table_model.setHorizontalHeaderLabels(data_frame.columns.tolist())
self.ui.profileTableView.horizontalHeader().setStretchLastSection(True)
# fill table model data
for row_idx in range(10): #len(data_frame.values)
row = list()
for col_idx in range(data_frame.columns.size):
val = QtGui.QStandardItem(str(data_frame.values[row_idx][col_idx]))
row.append(val) …
Run Code Online (Sandbox Code Playgroud) 我在 Windows 下遇到线程问题。
我正在开发一个程序,可以针对不同条件运行复杂的物理模拟。假设一年中每小时模拟 8760 次。我将每个线程的这些模拟进行分组,以便每个线程运行 273 个模拟的 for 循环(平均)
我为此任务购买了 16 核(32 线程)的 AMD ryzen 9 5950x。在 Linux 上,所有线程的使用率似乎都在 98% 到 100% 之间,而在 Windows 下我得到的是:
(第一条是读取数据的I/O线程,较小的条是进程线程。红色:同步,绿色:进程,紫色:I/O)
这是来自 Visual Studio 的并发可视化工具,它告诉我 63% 的时间花费在线程同步上。据我所知,我的代码对于 Linux 和 Windows 执行都是相同的。
我尽力使对象不可变以避免出现问题,这为我的旧 8 线程 intel i7 带来了巨大的收益。然而,当线程数量增多时,就会出现这个问题。
对于线程,我尝试了自定义并行和任务流库。两者对于我想做的事情表现相同。
Windows 线程是否存在产生这种行为的基本原理?
代码的自定义并行:
/**
* parallel for
* @tparam Index integer type
* @tparam Callable function type
* @param start start index of the loop
* @param end final +1 index of the loop …
Run Code Online (Sandbox Code Playgroud) 我在VS 2013社区版中有一个解决方案,我最近添加了一个Installshield限量版的安装项目.
当我重新构建解决方案时(在发布x64模式下),installshield项目会警告我以下文件:
Warning -6245: One or more of the project's components contain .NET properties that require the .NET Framework. It is recommended that the release include the .NET Framework. 16 ISEXP : warning : -6245: One or more of the project's components contain .NET properties that require the .NET Framework. It is recommended that the release include the .NET Framework.
Warning -6248: Could not find dependent file Microsoft.ServiceBus, or one of its dependencies of component PLATOS.Primary_output 18 ISEXP : …
Run Code Online (Sandbox Code Playgroud) 我有一个程序从csv文件加载配置文件并在表中显示数据.将pandas数据框加载到表中的速度很快,因为我使用了自定义模型实现QAbstractTableModel
,但是QTableView小部件的大小调整非常慢.
我该怎么做才能使调整大小和滚动更顺畅?
我已经用 Eigen 实现了一段代码,我希望 Eigen 使用 BLAS 和 LAPACK 。
我在这里看到,这是可能的,但我不知道如何或将这些值/指令放在代码中的位置。
我必须在某个地方指定价值,EIGEN_USE_BLAS
但我不知道在哪里。
我已经看到 Eigen 的源代码包括 BLAS 和 LAPACK 的代码,但我完全忽略它是否默认使用它或什么。我正在使用 Eigen 3.3.3。
我一直在研究一段代码来减少图形。问题是我想删除一些分支。删除分支后,我可以合并节点或不合并节点,具体取决于分支加入的节点之间的路径数。
也许下面的例子说明了我想要的:
我的代码如下:
from networkx import DiGraph, all_simple_paths, draw
from matplotlib import pyplot as plt
# data preparation
branches = [(2, 1),
(3, 2),
(4, 3),
(4, 13),
(7, 6),
(6, 5),
(5, 4),
(8, 7),
(9, 8),
(9, 10),
(10, 11),
(11, 12),
(12, 1),
(13, 9)]
branches_to_remove_idx = [11, 10, 9, 8, 6, 5, 3, 2, 0]
ft_dict = dict()
graph = DiGraph()
for i, br in enumerate(branches):
graph.add_edge(br[0], br[1])
ft_dict[i] = (br[0], br[1])
# Processing -----------------------------------------------------
for …
Run Code Online (Sandbox Code Playgroud) 我正在测试Extreme Optimization C#库,正是非线性系统求解器.作为一个例子,我发现我必须以下列形状传递非线性系统的求解器:
Func<Vector, double>[] f = {
x => Math.Exp(x[0])*Math.Cos(x[1]) - x[0]*x[0] + x[1]*x[1],
x => Math.Exp(x[0])*Math.Sin(x[1]) - 2*x[0]*x[1]
};
Run Code Online (Sandbox Code Playgroud)
问题是我尝试解决的系统无法在设计时指定.它是由负载流方程组成的非线性系统,用于求解交流电(AC)的电路.方程由许多变量组成,这些变量取决于网格中节点的数量,由用户指定,方程式如下:
所以基本上我每个节点有2个方程,这是2*n方程,由于它们依赖于i,j索引,因此不能在单行中组成,因此我必须有2个嵌套for循环来创建P和Q方程.
有没有办法创造Func<Vector, double>[] f = { equation system of variable lenght };
?
我在运行时看到了动态创建函数的帖子,但它没有回答我的问题(我相信)
//************************编辑**************************************
方程的创建是这样的:
For (int i=0; i< n; i++){
double A=0.0;
double B=0.0;
For (int j=0; j< n; j++){
A+= G[i,j]*Math.Cos(Theta[i,j]) + B[i,j]*Math.Sin(Theta[i,j])
B+= G[i,j]*Math.Sin(Theta[i,j]) + B[i,j]*Math.Cos(Theta[i,j])
}
P[i]=V[i]*A;
Q[i]=V[i]*B;
}
Run Code Online (Sandbox Code Playgroud)
当然A和B包含变量,而这个循环配方就没有多大意义了.
提前致谢.
我正在尝试开始使用Jenetics JAVA库进行遗传算法,而且我的GA有限背景中有一些我不理解的东西;
据我所知,GA生成了一组m
元素阵列,其中每个数组都是一个可以评估的潜在解决方案,一旦评估,潜在的解决方案就会被排序,最好的选择是为了创建一个新的人口,等等.但我发现Jenetics中的解决方案(基因型)是一个数组列表,其中每个数组都是我理解的潜在解决方案,每个数组也可以有不同的长度,我不明白为什么要使用这个结构而不是基因载体.
参见手册第6页,第3.1.3节.
如果可能的话我想知道为什么会这样.我希望这个问题足够明确.
由于以下代码,我从 PyQt5 切换到 PySide2 时遇到一些问题:
class EnumModel(QtCore.QAbstractListModel):
def __init__(self, list_of_enums):
"""
Enumeration model
:param list_of_enums: list of enumeration values to show
"""
QtCore.QAbstractListModel.__init__(self)
self.items = list_of_enums
def rowCount(self, parent=QtCore.QModelIndex()):
return len(self.items)
def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid() is True:
if role == QtCore.Qt.DisplayRole:
return QtCore.QVariant(self.items[index.row()].value[0])
elif role == QtCore.Qt.ItemDataRole:
return QtCore.QVariant(self.items[index.row()].value[0])
return QtCore.QVariant()
Run Code Online (Sandbox Code Playgroud)
代码在 PyQt5 下运行良好。
在我的迁移过程中我发现官方网站说:
PySide 仅支持 PyQt 的 API 2(请参阅 PSEP 101)了解详细信息。因此 Qt 类(例如 QStrings、QStringLists 和 QVariants)在 PySide 上不可用。相反,您应该简单地使用本机 Python 数据类型。
所以解决方案是(我猜)简单地更改QVariant
为str …
python ×4
pyqt4 ×2
.net ×1
blas ×1
c# ×1
c++ ×1
dynamic ×1
eigen3 ×1
function ×1
graph ×1
installation ×1
java ×1
jenetics ×1
lapack ×1
networkx ×1
pandas ×1
pyqt5 ×1
pyside2 ×1
python-3.5 ×1
python-3.x ×1
qtableview ×1
setup.py ×1
windows-10 ×1