Pycharm Debugging

Hi Team,

Hope someone can help me. I come from a .NET Visual studio background so please excuse me for this request.

Ive been with ERPNext for some time now, managed to install it a couple of times on Ubuntu. I have now managed to get through the tutorials nicely, and also managed to get the multi-tenant setup working, able to also create my own applications and add it to a site separate from erpnext default site.

My challenge now is setting up pycharm to debug the python code, both erpnext and my own applications I write using frappe. What I would like to learn now is how to configure pycharm to be able to click on ‘run’ and then be able to place a break point and inspect the python variables in pycharm.

I got as far as configuring the virtual environment but I dont know where to put the starting point of erpnext, or bench, or frappe.

I would really appreciate a beginners guide if someone could spare the time.

Thanking you in advance.

regards
Hemant

2 Likes

Hello,

In my pycharm I do this:

  • Start a Python Project
  • In Run/Debug configurations, I add: a Python Deftault…
  • On a new Python configuration:

Script: /usr/local/bin/bench
Script parameters: start
Working directory: /Users/fellipeh/Developer/python/frappe/frappe-bench

Don’t forget to set the correct virtualenv on PyCharm Configuration… set the “env” folder on frappe-bench directory.

After that, you can Run/Debug using PyCharm.

Cheers!

Hi fellipeh,

Thanks for your response.

Got it setup as you mention but getting this error:

/home/hemant/frappe-bench/env/bin/python /usr/local/bin/bench start
Traceback (most recent call last):
File “/usr/local/bin/bench”, line 5, in
from pkg_resources import load_entry_point
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 3074, in
@_call_aside
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 3060, in _call_aside
f(*args, **kwargs)
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 3087, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 645, in _build_master
ws.require(requires)
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 946, in require
needed = self.resolve(parse_requirements(requirements))
File “/home/hemant/frappe-bench/env/local/lib/python2.7/site-packages/pkg_resources/init.py”, line 833, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The ‘bench==0.1’ distribution was not found and is required by the application

Process finished with exit code 1

looks like its missing bench?

sorry still learning but will get there, just need a nudge in the right direction :wink:

regards

Ok, I have these problem too…

To solve that, I install bench in a root Python installation (system python), not only in virtualenv…

Hi Fellipeh,

Sorry if this sounds like a stupid question, cause I installed bench and erpnext using the install scripts, how do I install just bench in the python root?

Thanking you in advance.

regards
Hemant

Hi,

In main python (out side of virtual env), type this:

 git clone https://github.com/frappe/bench bench-repo
 sudo pip install -e bench-repo

Cheers!

Hi,

I did as your suggested but not sure if i was in the correct folder. Sorry i come from a windows many dev background and just starting to get my head around linux and python, so sorry for the noob questions.
2 issues

when i try to run in pycharm now still getting error saying it cannot find bench, and

When i try to run bench update from frappe folder i get permission errors.

Im sure i done something wrong.

Can you plz show me exactly how to install bench in root python folder including which folder or how to find the folder, cause i think this is where i went wrong.

Also, i got supervisor and ngnix running as the default install script for erpnext, do i need to switch that off, and how?

Thanking you in advance.

regards
Hemant

Sorry for my delay…

as I said, you need to run:

git clone https://github.com/frappe/bench bench-repo
sudo pip install -e bench-repo

without using any virtualenv… in other words… after you make a login, use these command.

If you receive a permission error, that’s because you installed something as root, and try to execute them using your user…

to install bench-repo in “system python” you need to be a root, or use “sudo” as showed…

Cheers

Hello,

I have configured Pycharm as per the above steps. I can start a debugging session but then the breakpoints are not being hit. I am using Pycharm community edition 4.5. What could i have missed ? I am not using a virtual environment

Regards

Hi @stevenyaga,

I use PyCharm Professional, do you cofirm to me if Community Edition can debug?

Hi @fellipeh

Yes, I use Community Edition to debug. But i had to use the python pdb library to have the breakpoints hit

Regards

Now something weird occurs here in my mac…

When I try to debug and/or run, I got these error:

/Users/fellipeh/Developer/frappe-bench/env/bin/python /usr/local/bin/bench start
dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/fellipeh/Developer/frappe-bench/env/bin/python
  Reason: image not found

Very, very weird… works fine until 2 weeks ago… :smiley:

@stevenyaga, how do you set the pdb library?

Hi @fellipeh,

See the below image of how i have created the configuration. For the pdb, it is as simple as doing this in your code

import pdb; pdb.set_trace()

Hi @stevenyaga, somehow, after update my PyCharm to version5, start works back… :smiley: without pdb… very, very suspicious… :smile:

Hi @fellipeh,

I have not been able to make it without pdb. Please share any configuration you might have done

Regards

Hi @stevenyaga,

Here is my config:

as I said, works fine now, but… I don’t know why start to work… if someone figure out what’s going on, tell me… :smiley:

1 Like

Hi @fellipeh,

Thanks, The only difference between your config and mine is the python interpreter path and the working directory. Even then, it does not work without the pdb. Very suspicious :smile:

Regards

For python interpreter, it’s the global python interpreter right ?

And for working directory is the location of erpnext code right ?

I follow you but my breakpoint still doesn’t hit.

Were you able to resolve this? I am having the same issue.

No, This is not yet resolved by me.