i've installed pycharm community edition 2016.
I tried to configure it to debug Odoo as illustrated in the capture
When i open a python file set a breakpoint and click debug icon i got an exception:
Also openerp, fields, api are underlined in red.
Any suggestions please. I use windows 8.1 as OS
Update:
According to Mariusz Answer , i'm now able to clic on debug bouton without any error.
Now i have put a brekpoint on a code to follow the execution, but the breakpoint is never reached ( the code is inside a buton method) while the method is executed. I can see the result in odoo page.
First question - you are not supposed to run it from exe file, but from openerp-server, which is located in odoo installation folder via python interpreter. What is more, your configuration is wrong, because Odoo does not work with Python 3.4.1
My configuration looks like this:
Second question - you need to add your sources folder in Project Structure configuration so it is recognized by PyCharm as a folder from which to import.
To be able to reach breakpoint you have to disable gevent. At the moment of writing you can do it by commenting this piece of code in openerp/__init__.py
import sys
evented = False
#if sys.modules.get("gevent") is not None:
# evented = True
Related
Background
Some time ago I seriously crashed my Windows computer while using PyCharm - I remember some errors about memory and then a hard crash with no blue screen - just black with some thin vertical lines and reboot to Windows installation / fixing screen. Since then, I had this problem, with no way I found online to fix this.
Edit : Apparently, this has nothing to do with the problem.
The problem
Whenever I open a project, or create a new one, an error appears with the Invalid Python SDK error message.
**Invalid Python SDK**
Cannot set up a Python SDKat Python 3.9 (%projectName%) (%projectPath%).The SDK seems to be invalid.
Also, this is what the work environment looks like the moment I close this message. In the Project window, the venv directory (and every directory under it) is marked as an Exclusion, and in the code, the print(f'Hi, {name}') function is marked as an unresolved reference error shown below. The program, however, executes flawlessly.
What's more, when I go to Python Interpreter settings at File -> Settings -> Project -> Python Interpreter there's a yellow bar on the bottom which says:
Non-zero exit code (4).
which after some time says:
Python packaging tools not found.
Upon installing, nothing changes, and I can't add packages from this screen (the '+' button is greyed out):
When I try to check Python interpreter paths, there are no paths shown, and I don't know what that means:
In short, all of the default Python functions like print are marked as errors, even though they work when executed. This makes coding extremely confusing, as I can't quickly distinguish between real errors and 'errors'.
The search for solution
Normally this would be a problem with interpreter set-up or path, but I've tried most of the methods proposed in other answers to similar questions. To name a few :
PyCharm shows unresolved references error for valid code
'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation
Why do I get an 'SDK seems invalid' error when setting up my Project Interpreter in PyCharm?
Invalid Python SDK Error while using python 3.4 on PyCharm
Invalid Python SDK when setting a venv
There were supposed to be links, but I don't have enough reputation on Stack Overflow to post them with the questions. These, however, can be easily looked up in Google, all of them are posted to Stack Overflow.
What I tried
I should mention that the first things I tried were removing and installing PyCharm, all user configurations and Python itself as well. I installed Python from the official site, and from the PyCharm application, both methods ended with the same result.
File -> Invalidate Caches... -> Invalidate and restart. Didn't work.
Checking file interpreter in Edit Configurations. Don't know what to make of it. The result:
Refreshing the interpreter paths. Even now, the paths yield no results.
Removing the interpreter and adding it again. No result.
Deleting the .idea folder. No result.
Deleting PyCharm user preferences under %homepath%/.PyCharm50. I don't have that folder though.
Switching interpreter back and forth. No result.
Creating a new interpreter in a different location. No result.
Marking project directory as root ProjectName -> Mark Directory as -> Sources Root and unmarking other directories as Excluded. No result.
Using no interpreter. Yeah, it doesn't mark non-errors as errors anymore. But the code doesn't work. That's not a solution for me.
Checking if venv/pyvenv.cfg has paths set correctly. These look fine to me.
Checking Windows environment variables - Path variable. It was in the user section, but wasn't in the system section. I added it, restarted but still no result.
Changing account name in Windows. My account name was 'username' and that's how my User folder is called `C:\Users\username', but I later connected it to Microsoft account and my user name is now User Name with a space and I can't really change it. My folder stayed the same. Not sure if I can fix it that way.
To the two last things I tried I should also add that I changed my Windows username from 'username' to 'user name' with a space, but that wasn't until recently.
I'm attaching the idea.log file for you to check. I replaced my real username with 'User Name' to highlight the existence of a space.
OK, that was a lucky one! I'm thus posting my comment as an answer:
The problem is caused by the non-ASCII characters in the path, and the solution is to remove them. As indicated by #TheLazyScripter this is a known issue.
I installed Intellij 2019 with python plugin. And I opened a directory with python scripts. I'm going to debug script1.py in the directory.
In the "Project Structure" window, I added new Python in the field "Project SDK".
Then, I went to "Run/Debug configurations" folder and clicked the + and added a new Application, I need an command line argument so I filled the field "Program arguments:" with my arguments.
However, at the bottom it shows a read error message: "Error: No main class specified". And I cannot run the python script. What I missed to set up the intellij to run python script?
You need to use Python run configuration instead. Although creating run configurations manually is inconvenient and I would recommend using a context menu or a shortcut so that IDE does it automatically:
See https://www.jetbrains.com/help/pycharm/running-applications.html for more details.
I am doing simple python coding in pycharm but the problem is whenever I debug it starts debugging some other file in my project and not the one I am working with.
I did go to run-->edit configuration and check if my file was set for debugging and it was but still it debugs another file when I start debugging.
any help will be appreciated
If you debug using pressing SHIFT-F9 it debugs the last file you debugged, which might be some file you debugged yesterday...
To debug a new file press ALT-SHIF-F9.
You can see these two different debugging options from the Run menu. There is Debug <last file> and there is Debug...
I think you can do it with Right clicking on body of codes and select your project name form there.
Also can select Run > Debug
you can debug it line by line from here
The saving python files with the python module name causing debugging issues.
Replace the files with other name it will work.
How do you go about debug Blender Python in Eclipse and PyDev?
What I have tried is:
http://www.luxrender.net/wiki/LuxBlend25_Debugging_with_eclipse
http://www.blender.org/forum/viewtopic.php?t=3914&sid=717a127d12596f89e4aea0c54938ef80
But non of then seams to work?
Regards
There is very good e-book written by Witold Jaworski about Blender add-on programming. It includes chapters with step by step instructions how to setup Eclipce with PyDev to debug Blender add-ons.
Programming Add-ons for Blender 2.5
Here is how I setup debug, which is slight different but based on the lux-render tutorial.
First, create the a .py file, lets call it debug.py, which will contain a function which we will call later to setup debugging. Put this file in the same folder as the main __init__.py of your module. As per the lux-renderer tutorial, add the following code, updating PYDEV_SOURCE_DIR.
import sys
def startdebug():
try:
# set the PYDEV_SOURCE_DIR correctly before using the debugger
PYDEV_SOURCE_DIR = 'C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc'
# test if PYDEV_SOURCE_DIR already in sys.path, otherwise append it
if sys.path.count(PYDEV_SOURCE_DIR) < 1:
sys.path.append(PYDEV_SOURCE_DIR)
# import pydevd module
import pydevd
# set debugging enabled
pydevd.settrace(None, True, True, 5678, False, False)
except:
pass
When setting the PYDEV_SOURCE_DIR ensure you point it to the org.python.pydev.debug_xxxxx. There is another folder similiar to this. To ensure you have the correct folder it will contain a /pysrc folder.
Now in your main __init__.py, this must come before any other import statements to work correctly. Add the following directly under the bl_info section, as strangely blender parses this itself.
DEBUGGING = True
if(DEBUGGING):
import debug
debug.startdebug()
Having it here will avoids adding per file traces like the lux-render tutorial.
Add some breakpoint to the version in the add-ons folder,
Switch to the debug perspective,
Start Eclipses debug server,
Start blender
Run the script and it will hit the breakpoint.
The common problems I find people encounter:
pointing the path to the wrong pydev debug folder, ensure that there is a /pysrc folder
When Pydev updates, update the PYDEV_SOURCE_DIR as the debug_xxxxx will have change
not having eclipse server running,
setting breakpoints on a local copy of the files instead of the version in the blender add-on directory
saving the script does not mean that blender will reload it, use imp, disable/renable the add-on or restart Blender.
There are quite comprehensive instructions for setting up blender and eclipse for debugging.
http://wiki.blender.org/index.php/User:Z0r/PyDevAndProfiling
While this is for blenders game engine, much of it applies to regular blender.
Is it possible?
By debug I mean setting breakpoints, inspect values and advance step by step.
You can do remote debugging of python web apps over TCP/IP with winpdb.
(Link appears down as of June 2019. Try PyPI winpdb)
I haven't used web2py, but if it runs in a terminal window, you can use standard pdb stuff. Add this line somewhere in your code:
import pdb; pdb.set_trace()
This will invoke the debugger and break. Then you can use PDB commands: n to step to the next line, l to list code, s to step into a function, p to print values, etc.
One can debug applications built on Web2py using the following set-up:
Eclipse IDE
Install Pydev into Eclipse
Set Breakpoints on your code as needed
Within Eclipse right-click the file web2py.py and select Debug As -> Python Run
When a breakpoint is hit Eclipse will jump to the breakpoint where you can inspect variables and step thru the code
You can also use Visual Studio 2010. Here's how:
Download and install Python Tools for Visual Studio.
Create a new project from existing code (File > New > Project From Existing Code...)
Specify your web2py folder and use the defaults.
Right-click on web2py.py and choose Set as Startup File.
Set breakpoints and hit F5 (run) or right-click on web2py.py and choose Start with Debugging.
This is a nice setup if you already use visual studio.
Yes, it is possible, Due to the "span prevention" I am still not allowed to post screenshots, but here is a full screenshot hosted at my website:
http://static.techfuel.net/debug_web2py.png
I'm debugging web2py applications with Eclipse and PyDev. Here is an article:
http://www.web2pyslices.com/main/slices/take_slice/2
Here is an article on debugging python with pdb, which will work with web2py. http://sontek.net/debugging-python-with-pdb
As Carl stated, it is as easy as:
Installing PyDev in Eclipse
Right Click on your Web2Py project, selecting Debug As > Python Run
Selecting web2py.py as the file to run
No other plugins or downloads are needed.
#Ned Batchelder is almost right, but the standard way of doing it in web2py is slightly different.
Instead of `import pdb; pdb.set_trace(), you use the code:
from gluon.debug import dbg
dbg.set_trace()
When executing the web application, the application will freeze when it reaches this section of code. You then go to http://127.0.0.1:8000/admin/debug/interact (using the root URL for your application) and it will show a fully interactive, web based debugger:
See documentation.