Reputation: 2885
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)\JetBrains\PyCharm 2016.1\helpers\pydev\pydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\Program Files (x86)\JetBrains\PyCharm 2016.1\helpers\pydev\pydevd.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)\JetBrains\PyCharm 2016.1\helpers\pydev\pydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "D:\Program Files (x86)\JetBrains\PyCharm 2016.1\helpers\pydev\pydevd.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/BMDanalyse\ViewBoxCustom.py", line 68, in <module>
class MultiRoiViewBox(pg.ViewBox):
File "D:/Home/Documents/PycharmProjects/BMDanalyse/BMDanalyse\ViewBoxCustom.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_())
Upvotes: 2
Views: 1775
Reputation: 2885
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.
Upvotes: 1
Reputation: 5207
I'm guessing it's because of your .idea
folder/file.
Click the Run
option in the menu bar of pycharm.
Click Edit Configurations..
.
Verify that the options for your interpreter are correct for your environment. You will probably have to switch this each time you switch operating systems since pycharm saves your configuration on a project basis, in that .idea
folder/file.
If this doesn't work, backup your .idea
folder/file and then delete it. Then open the project in pycharm and see if that resolves the issue.
If neither of these things works, then you are dealing with something on Jetbrains end that probably isn't solvable. Since you are using pyqt, I'm guessing something is not meshing well with the debugger.
Upvotes: 0