Pycharm debugger works on Ubuntu but not on Windows for identical code(Pycharm 调试器可在 Ubuntu 上运行,但不能在 Windows 上运行相同的代码)
问题描述
更新:正在跟踪的问题这里p>
我可能不是唯一遇到此问题的人.我错过了今天也发布的这个,它看起来很相关:PyCharm 调试器不起作用
以下是使用 Pycharm Professional 时在 Windows 7 和 Ubuntu 14.04 上运行良好的最小示例
PyCharm 2016.1构建 #PY-145.260,构建于 2016 年 3 月 22 日JRE:1.8.0_60-b27 x86JVM:Oracle Corporation 的 Java HotSpot(TM) 服务器 VM
现在是超级奇怪的部分:在 Ubuntu 的 Pycharm 调试器上,我没有遇到任何问题.但是,在 Window 的 Pycharm 调试器中,我得到了以下回溯(即使代码在不调试时运行良好!):
Traceback(最近一次调用最后一次):文件D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py",第 1530 行,在 <module>globals = debugger.run(setup['file'], None, None, is_module)文件D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py",第 937 行,运行中pydev_imports.execfile(file, globals, locals) # 执行脚本<module> 中的文件C:/Users/Cornelis/PycharmProjects/SO-Help/test.py",第 11 行类主窗口(QtGui.QMainWindow):MainWindow 中的文件C:/Users/Cornelis/PycharmProjects/SO-Help/test.py",第 58 行@QtCore.pyqtSlot(int, int)AttributeError:模块"对象没有属性pyqtSlot"后端 TkAgg 是交互式后端.打开交互模式.
我什至不知道我应该如何开始调试,因为我以前从未见过这样的事情发生!如果您的程序在您运行它时工作但在您尝试调试它时却没有,而且它在另一个操作系统上调试得很好,这到底意味着什么?这只能是一个 Pycharm 错误吗?上面的回溯与我在主程序中得到的并不完全相同,但却是我能得到的最接近的.以下是我在完整程序中看到的回溯:
Backend TkAgg 是交互式后端.打开交互模式.回溯(最近一次通话最后):文件D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py",第 1530 行,在 <module>globals = debugger.run(setup['file'], None, None, is_module)文件D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py",第 937 行,运行中pydev_imports.execfile(file, globals, locals) # 执行脚本<module> 中的文件D:/Home/Documents/PycharmProjects/BMDanalysis/BMDanalysis/SPCanalysis.py",第 22 行从 ViewBoxCustom 导入 MultiRoiViewBox、ImageAnalysisViewBox<module> 中的文件D:/Home/Documents/PycharmProjects/BMD analyze/BMD analyzeViewBoxCustom.py",第 68 行类 MultiRoiViewBox(pg.ViewBox):MultiRoiViewBox 中的文件D:/Home/Documents/PycharmProjects/BMD analyze/BMD analyzeViewBoxCustom.py",第 71 行点击 = QtCore.pyqtSignal(int, int)AttributeError:模块"对象没有属性pyqtSignal"
这是您的最小示例.只需复制并粘贴并单击 ViewBox.如果您运行它,应该会出现一个随机图像.但是如果你调试它,它就会爆炸.
导入 os, sys, matplotlib, matplotlib.pyplot将 numpy 导入为 np从 pyqtgraph.Qt 导入 QtCore、QtGui从 pyqtgraph.widgets.GraphicsLayoutWidget 导入 GraphicsLayoutWidget将 pyqtgraph 导入为 pg将 pyqtgraph.functions 导入为 fnN = 256ARR = np.random.random((N,N))*255类主窗口(QtGui.QMainWindow):def __init__(self, parent=None):QtGui.QMainWindow.__init__(self, parent)self.setupUserInterface()self.setupSignals()def setupUserInterface(self):"""初始化用户界面"""# 左框架leftFrame = QtGui.QFrame()leftFrameLayout = QtGui.QHBoxLayout()leftFrame.setLayout(leftFrameLayout)leftFrame.setLineWidth(0)leftFrame.setFrameStyle(QtGui.QFrame.Panel)leftFrameLayout.setContentsMargins(0,0,5,0)# 左帧内容self.viewMain = GraphicsLayoutWidget() # GraphicsView 中的 GraphicsLayoutleftFrameLayout.addWidget(self.viewMain)self.viewMain.setMinimumSize(200,200)self.vb = MultiRoiViewBox(lockAspect=True,enableMenu=True)self.viewMain.addItem(self.vb)self.vb.enableAutoRange()# 右边框self.sidePanel = SidePanel(自我)# UI 窗口(包含左右框架)UIwindow = QtGui.QWidget(self)UIwindowLayout = QtGui.QHBoxLayout()UIwindowSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal)UIwindowLayout.addWidget(UIwindowSplitter)UIwindow.setLayout(UIwindowLayout)self.setCentralWidget(UIwindow)UIwindowSplitter.addWidget(leftFrame)UIwindowSplitter.addWidget(self.sidePanel)self.setMinimumSize(600,500)self.resize(self.minimumSize())def setupSignals(self):""" 设置信号 """# self.sidePanel.buttImageAdd.clicked.connect(self.showImage)self.vb.clicked.connect(self.on_vbc_clicked)@QtCore.pyqtSlot(int, int)def on_vbc_clicked(self, x, y):打印(x)打印(y)self.showImage()定义显示图像(自我):""" 在主视图中显示图像 """self.vb.showImage(ARR)类视图模式():def __init__(self,id,cmap):自我.id = idself.cmap = cmapself.getLookupTable()def getLookupTable(self):lut = [ [ int(255*val) for val in self.cmap(i)[:3] ] for i in xrange(256) ]lut = np.array(lut,dtype=np.ubyte)self.lut = lut类 MultiRoiViewBox(pg.ViewBox):sigROIchanged = QtCore.Signal(object)点击 = QtCore.pyqtSignal(int, int)def __init__(self,parent=None,border=None,lockAspect=False,enableMouse=True,invertY=False,enableMenu=True,name=None):pg.ViewBox.__init__(self,parent,border,lockAspect,enableMouse,invertY,enableMenu,name)self.img = 无self.NORMAL = ViewMode(0,matplotlib.cm.gray)self.DEXA = ViewMode(1,matplotlib.cm.jet)self.viewMode = self.NORMALdef showImage(self,arr):如果 arr==无:self.img = 无返回如果 self.img==None:self.img = pg.ImageItem(arr,autoRange=False,autoLevels=False)self.addItem(self.img)self.img.setImage(arr,autoLevels=False)self.updateView()定义更新视图(自我):self.background.setBrush(fn.mkBrush(self.viewMode.lut[0]))self.background.show()如果 self.img==None:返回否则:self.img.setLookupTable(self.viewMode.lut)def mouseClickEvent(self, ev):如果 ev.button() == QtCore.Qt.RightButton 和 self.menuEnabled():ev.accept()self.raiseContextMenu(ev)elif ev.button() == QtCore.Qt.LeftButton:ev.accept()pos = self.mapToItem(self.img, ev.pos())self.clicked.emit(pos.x(), pos.y())从 pyqtgraph.Qt 导入 QtCore,QtGui侧面板类(QtGui.QWidget):def __init__(self, parent=None):QtGui.QWidget.__init__(self,parent)self.setMinimumWidth(250)self.buttMinimumSize = QtCore.QSize(36,36)self.setupImageToolbox()sidePanelLayout = QtGui.QVBoxLayout()sidePanelLayout.addWidget(self.imageToolbox)sidePanelLayout.setContentsMargins(0,0,0,0)self.setLayout(sidePanelLayout)def setupImageToolbox(self):# 图片按钮self.buttImageAdd = QtGui.QPushButton()imageButtons = [self.buttImageAdd]对于我在 xrange(len(imageButtons)):图像 = 图像按钮 [i]image.setMinimumSize(self.buttMinimumSize)self.imageFileTools = QtGui.QFrame()imageFileToolsLayout = QtGui.QHBoxLayout()self.imageFileTools.setLayout(imageFileToolsLayout)self.imageFileTools.setLineWidth(1)self.imageFileTools.setFrameStyle(QtGui.QFrame.StyledPanel)imageFileToolsLayout.addWidget(self.buttImageAdd)# 图片工具箱(包含 imageFileList + imageFileList 按钮)self.imageToolbox = QtGui.QFrame()self.imageToolbox.setLineWidth(2)self.imageToolbox.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Raised)imageToolboxLayout = QtGui.QVBoxLayout()self.imageToolbox.setLayout(imageToolboxLayout)imageToolboxLayout.addWidget(self.imageFileTools)如果 __name__ == "__main__":应用程序 = QtGui.QApplication(sys.argv)窗口 = 主窗口()窗口.show()sys.exit(app.exec_())
重新安装Pycharm并从头重新设置python包后问题已解决,除了这次使用python 64位(之前使用32位).此外,我使用的是 Continuum Analytics 的 python 包管理器.我不再使用它,所以这也可能是罪魁祸首.
Update: Issue being tracked here
Edit: I may not be the only one with this issue. I missed this which was also posted today and it looks related: PyCharm debugger doesn't work
Below is a minimal example that runs fine on both Windows 7 and Ubuntu 14.04 when using Pycharm Professional
PyCharm 2016.1
Build #PY-145.260, built on March 22, 2016
JRE: 1.8.0_60-b27 x86
JVM: Java HotSpot(TM) Server VM by Oracle Corporation
Now the uber-weird part: On Ubuntu's Pycharm debugger I get no issue. However, in Window's Pycharm debugger I get the following traceback (even though the code runs fine when not debugging!):
Traceback (most recent call last):
File "D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py", line 937, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/Cornelis/PycharmProjects/SO-Help/test.py", line 11, in <module>
class MainWindow(QtGui.QMainWindow):
File "C:/Users/Cornelis/PycharmProjects/SO-Help/test.py", line 58, in MainWindow
@QtCore.pyqtSlot(int, int)
AttributeError: 'module' object has no attribute 'pyqtSlot'
Backend TkAgg is interactive backend. Turning interactive mode on.
I don't even know how I'm supposed to start debugging since I've never seen something like this happen before! What in the world does it mean if your program works when you run it but not when you try to debug it and moreover that it debugs fine on another OS? Can this only be a Pycharm bug? The above traceback isn't exactly identical to what I get in my main program but is the closest I could get. Below is the traceback I see in my full program:
Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
File "D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "D:Program Files (x86)JetBrainsPyCharm 2016.1helperspydevpydevd.py", line 937, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "D:/Home/Documents/PycharmProjects/BMDanalyse/BMDanalyse/SPCanalyse.py", line 22, in <module>
from ViewBoxCustom import MultiRoiViewBox, ImageAnalysisViewBox
File "D:/Home/Documents/PycharmProjects/BMDanalyse/BMDanalyseViewBoxCustom.py", line 68, in <module>
class MultiRoiViewBox(pg.ViewBox):
File "D:/Home/Documents/PycharmProjects/BMDanalyse/BMDanalyseViewBoxCustom.py", line 71, in MultiRoiViewBox
clicked = QtCore.pyqtSignal(int, int)
AttributeError: 'module' object has no attribute 'pyqtSignal'
Here is your minimal example. Just copy and paste and click the ViewBox. A random image should appear if you run it. But if you debug it, it blows up.
import os, sys, matplotlib, matplotlib.pyplot
import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
from pyqtgraph.widgets.GraphicsLayoutWidget import GraphicsLayoutWidget
import pyqtgraph as pg
import pyqtgraph.functions as fn
N = 256
ARR = np.random.random((N,N))*255
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.setupUserInterface()
self.setupSignals()
def setupUserInterface(self):
""" Initialise the User Interface """
# Left frame
leftFrame = QtGui.QFrame()
leftFrameLayout = QtGui.QHBoxLayout()
leftFrame.setLayout(leftFrameLayout)
leftFrame.setLineWidth(0)
leftFrame.setFrameStyle(QtGui.QFrame.Panel)
leftFrameLayout.setContentsMargins(0,0,5,0)
# Left frame contents
self.viewMain = GraphicsLayoutWidget() # A GraphicsLayout within a GraphicsView
leftFrameLayout.addWidget(self.viewMain)
self.viewMain.setMinimumSize(200,200)
self.vb = MultiRoiViewBox(lockAspect=True,enableMenu=True)
self.viewMain.addItem(self.vb)
self.vb.enableAutoRange()
# Right frame
self.sidePanel = SidePanel(self)
# UI window (containing left and right frames)
UIwindow = QtGui.QWidget(self)
UIwindowLayout = QtGui.QHBoxLayout()
UIwindowSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
UIwindowLayout.addWidget(UIwindowSplitter)
UIwindow.setLayout(UIwindowLayout)
self.setCentralWidget(UIwindow)
UIwindowSplitter.addWidget(leftFrame)
UIwindowSplitter.addWidget(self.sidePanel)
self.setMinimumSize(600,500)
self.resize(self.minimumSize())
def setupSignals(self):
""" Setup signals """
# self.sidePanel.buttImageAdd.clicked.connect(self.showImage)
self.vb.clicked.connect(self.on_vbc_clicked)
@QtCore.pyqtSlot(int, int)
def on_vbc_clicked(self, x, y):
print(x)
print(y)
self.showImage()
def showImage(self):
""" Shows image in main view """
self.vb.showImage(ARR)
class ViewMode():
def __init__(self,id,cmap):
self.id = id
self.cmap = cmap
self.getLookupTable()
def getLookupTable(self):
lut = [ [ int(255*val) for val in self.cmap(i)[:3] ] for i in xrange(256) ]
lut = np.array(lut,dtype=np.ubyte)
self.lut = lut
class MultiRoiViewBox(pg.ViewBox):
sigROIchanged = QtCore.Signal(object)
clicked = QtCore.pyqtSignal(int, int)
def __init__(self,parent=None,border=None,lockAspect=False,enableMouse=True,invertY=False,enableMenu=True,name=None):
pg.ViewBox.__init__(self,parent,border,lockAspect,enableMouse,invertY,enableMenu,name)
self.img = None
self.NORMAL = ViewMode(0,matplotlib.cm.gray)
self.DEXA = ViewMode(1,matplotlib.cm.jet)
self.viewMode = self.NORMAL
def showImage(self,arr):
if arr==None:
self.img = None
return
if self.img==None:
self.img = pg.ImageItem(arr,autoRange=False,autoLevels=False)
self.addItem(self.img)
self.img.setImage(arr,autoLevels=False)
self.updateView()
def updateView(self):
self.background.setBrush(fn.mkBrush(self.viewMode.lut[0]))
self.background.show()
if self.img==None: return
else: self.img.setLookupTable(self.viewMode.lut)
def mouseClickEvent(self, ev):
if ev.button() == QtCore.Qt.RightButton and self.menuEnabled():
ev.accept()
self.raiseContextMenu(ev)
elif ev.button() == QtCore.Qt.LeftButton:
ev.accept()
pos = self.mapToItem(self.img, ev.pos())
self.clicked.emit(pos.x(), pos.y())
from pyqtgraph.Qt import QtCore,QtGui
class SidePanel(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self,parent)
self.setMinimumWidth(250)
self.buttMinimumSize = QtCore.QSize(36,36)
self.setupImageToolbox()
sidePanelLayout = QtGui.QVBoxLayout()
sidePanelLayout.addWidget(self.imageToolbox)
sidePanelLayout.setContentsMargins(0,0,0,0)
self.setLayout(sidePanelLayout)
def setupImageToolbox(self):
# Image buttons
self.buttImageAdd = QtGui.QPushButton()
imageButtons = [self.buttImageAdd]
for i in xrange(len(imageButtons)):
image = imageButtons[i]
image.setMinimumSize(self.buttMinimumSize)
self.imageFileTools = QtGui.QFrame()
imageFileToolsLayout = QtGui.QHBoxLayout()
self.imageFileTools.setLayout(imageFileToolsLayout)
self.imageFileTools.setLineWidth(1)
self.imageFileTools.setFrameStyle(QtGui.QFrame.StyledPanel)
imageFileToolsLayout.addWidget(self.buttImageAdd)
# Image Toolbox (containing imageFileList + imageFileList buttons)
self.imageToolbox = QtGui.QFrame()
self.imageToolbox.setLineWidth(2)
self.imageToolbox.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Raised)
imageToolboxLayout = QtGui.QVBoxLayout()
self.imageToolbox.setLayout(imageToolboxLayout)
imageToolboxLayout.addWidget(self.imageFileTools)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
The issue has been resolved after reinstalling Pycharm and setting up python packages again from scratch, except this time using python 64-bit (was using 32-bit before). Moreover, I was using Continuum Analytics's python package manager. I no longer use it so that might also have been the culprit.
这篇关于Pycharm 调试器可在 Ubuntu 上运行,但不能在 Windows 上运行相同的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Pycharm 调试器可在 Ubuntu 上运行,但不能在 Windo
基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 筛选NumPy数组 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01