PyCharm setup with Slicer

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

PyCharm setup with Slicer

jphong
This post has NOT been accepted by the mailing list yet.
Hi, Slicer developers!
I am currently involved in a research project, called slicerSALT to develop shape analysis modules using Slicer.
As a first step, I am now trying to write a simple python extension to get myself familiar with both Slicer extension workflow and python. I am trying to use PyCharm as my IDEs.
I added Slicer/Base/Python under File->Settings->Project Structure->Add Content Root.
However, I ran into a couple of issues that seem to be related:

The first issue is that PyCharm complains about imports on qt and ctk (the message when I hover over are "No Module named qt" and "No Module named ctk" respectively). I am guessing that I am missing some environment settings to make PyCharm exposed to qt and ctk but I am not too sure on how to resolve this.

The second issue is that when I open PyCharm built-in Python Console and type import slicer myself, then I get the messages saying:
No module named MRMLCLIPython
No module named vtkTeemPython
No module named qMRMLWidgetsPythonQt
No module named SlicerBaseLogicPython
No module named qSlicerBaseQTCorePythonQt
No module named qSlicerBaseQTGUIPythonQt
No module named qSlicerBaseQTAppPythonQt
No module named qSlicerBaseQTCLIPython
No module named qSlicerBaseQTCLIPythonQt
 I can see those libraries under Slicer-SuperBuild-Debug/Slicer-build/bin directory. I tried adding Slicer-SuperBuild-Debug/Slicer-build/bin as part of interpreter search path but it did not help...

Can anyone please help me resolve these issues? I have attached the screenshot at the bottom to help illustrate the problem better.

Thank you in advance for your help!

Sincerely,
-JP

Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

Steve Pieper-2
Hi JP - 

You don't run slicer code directly in pycharm - instead you connect to the remote debugger.

See the info here:


HTH,
Steve

On Tue, Mar 7, 2017 at 6:35 PM, jphong <[hidden email]> wrote:
Hi, Slicer developers!
I am currently involved in a research project, called slicerSALT to develop
shape analysis modules using Slicer.
As a first step, I am now trying to write a simple python extension to get
myself familiar with both Slicer extension workflow and python. I am trying
to use PyCharm as my IDEs.
I added Slicer/Base/Python under File->Settings->Project Structure->Add
Content Root.
However, I ran into a couple of issues that seem to be related:

The first issue is that PyCharm complains about imports on qt and ctk (the
message when I hover over are "No Module named qt" and "No Module named ctk"
respectively). I am guessing that I am missing some environment settings to
make PyCharm exposed to qt and ctk but I am not too sure on how to resolve
this.

The second issue is that when I open PyCharm built-in Python Console and
type /import slicer/ myself, then I get the messages saying:
/No module named MRMLCLIPython
No module named vtkTeemPython
No module named qMRMLWidgetsPythonQt
No module named SlicerBaseLogicPython
No module named qSlicerBaseQTCorePythonQt
No module named qSlicerBaseQTGUIPythonQt
No module named qSlicerBaseQTAppPythonQt
No module named qSlicerBaseQTCLIPython
No module named qSlicerBaseQTCLIPythonQt
/ I can see those libraries under Slicer-SuperBuild-Debug/Slicer-build/bin
directory. I tried adding Slicer-SuperBuild-Debug/Slicer-build/bin as part
of interpreter search path but it did not help...

Can anyone please help me resolve these issues? I have attached the
screenshot at the bottom to help illustrate the problem better.

Thank you in advance for your help!

Sincerely,
-JP

<http://slicer-devel.65872.n3.nabble.com/file/n4038200/54.png>



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/PyCharm-setup-with-Slicer-tp4038200.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ


_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

jphong
Hi, Steve

First of all, thank you for responding to my question!
But I do understand that you don't run slicer code in PyCharm; you load it
in Slicer and run it inside Slicer.
What I want to achieve is to utilize PyCharm's code completion while I am
editing Slicer code (Pardon me for not being clear on what I want to
achieve). Wouldn't DebuggingTools Extension only allow me to use code
completion in debug mode?

And I would expect that if I had set up my PyCharm project correctly then I
should be able to execute simple statements such as /import slicer/ in
built-in python console. But currently it seems to me that my PyCharm
project is missing links to these libraries (e.g., MRMLCLIPython) based on
the messages I get from the built-in console. Or am I
misunderstanding/missing something completely?

I have also looked at the previous post on the mailing list by JC
(http://massmail.spl.harvard.edu/public-archives/slicer-devel/2015/038853.html)
on this matter. And JC seems to be addressing the issue (how to make sure
that you can import CTK and QT properly in PyCharm), but I do not know the
specific steps to accomplish that which seemed to be implied...
I have little experience in both python and Slicer. And  pardon me if the
question seems to be too basic.

Thank you in advance for your time and help!
Sincerely,
-JP



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/PyCharm-setup-with-Slicer-tp4038200p4038203.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

lasso2
I've tried getting code completion in PyCharm a couple of times during the last few years, but it's difficult to set up, not all libraries are supported, and even if you have auto-completion, it doesn't help much, because PyCharm's heuristic of guessing variable types is not very good (at least not for wrapped C++ classes and our Python scripts).

To get exactly known, correct variable types, auto-complete, interactive console, variable watch, stack trace, etc. you just connect your debugger to Slicer and add a breakpoint in the method that you are developing.

Andras

-----Original Message-----
From: slicer-devel [mailto:[hidden email]] On Behalf Of jphong
Sent: March 7, 2017 21:02
To: SPL Slicer Devel <[hidden email]>
Subject: Re: [slicer-devel] PyCharm setup with Slicer

Hi, Steve

First of all, thank you for responding to my question!
But I do understand that you don't run slicer code in PyCharm; you load it in Slicer and run it inside Slicer.
What I want to achieve is to utilize PyCharm's code completion while I am editing Slicer code (Pardon me for not being clear on what I want to achieve). Wouldn't DebuggingTools Extension only allow me to use code completion in debug mode?

And I would expect that if I had set up my PyCharm project correctly then I should be able to execute simple statements such as /import slicer/ in built-in python console. But currently it seems to me that my PyCharm project is missing links to these libraries (e.g., MRMLCLIPython) based on the messages I get from the built-in console. Or am I misunderstanding/missing something completely?

I have also looked at the previous post on the mailing list by JC
(http://massmail.spl.harvard.edu/public-archives/slicer-devel/2015/038853.html)
on this matter. And JC seems to be addressing the issue (how to make sure that you can import CTK and QT properly in PyCharm), but I do not know the specific steps to accomplish that which seemed to be implied...
I have little experience in both python and Slicer. And  pardon me if the question seems to be too basic.

Thank you in advance for your time and help!
Sincerely,
-JP



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/PyCharm-setup-with-Slicer-tp4038200p4038203.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

jphong
Hi Andras,

I see. I guess using PyCharm in debug mode could be an option.
Does PyDev with LiClipse suffer somewhat similar problems (e.g., not being
able to load certain libraries, and auto-complete heuristics not being too
good)?

Sincerely,
-JP



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/PyCharm-setup-with-Slicer-tp4038200p4038206.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

jphong
This post has NOT been accepted by the mailing list yet.
In reply to this post by lasso2
Hi Andras,

I see. I guess using PyCharm in debug mode could be an option.
Does PyDev with LiClipse suffer somewhat similar problems (e.g., not being able to load certain libraries, and auto-complete heuristics not being too good)?

Sincerely,
-JP
Reply | Threaded
Open this post in threaded view
|

Re: PyCharm setup with Slicer

lasso2
In reply to this post by jphong
LiClipse seemed to be a bit better in guessing variable types and getting documentation for VTK classes (but again, reading VTK documentation in a web browser is about as good or better).

Another advantage of LiClipse is that "set next statement" is available during debugging, which allows you to re-run or skip lines.

Andras

-----Original Message-----
From: slicer-devel [mailto:[hidden email]] On Behalf Of jphong
Sent: March 7, 2017 22:20
To: SPL Slicer Devel <[hidden email]>
Subject: Re: [slicer-devel] PyCharm setup with Slicer

Hi Andras,

I see. I guess using PyCharm in debug mode could be an option.
Does PyDev with LiClipse suffer somewhat similar problems (e.g., not being able to load certain libraries, and auto-complete heuristics not being too good)?

Sincerely,
-JP



--
View this message in context: http://slicer-devel.65872.n3.nabble.com/PyCharm-setup-with-Slicer-tp4038200p4038206.html
Sent from the slicer-devel mailing list archive at Nabble.com.
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ