I'm trying to setup a good VSCode python environment for debugging including profiling using cProfile in a REPL manner, and I really like the debug widow.
In the VSCode debugger I am able to run/debug the following script:
import cProfile
cProfile.run("10 + 10")
print("Break here")
I am using the Microsoft "Python" extension for debugging and setting the output to "internalConsole" in my "launch.json" and the cProfile output correctly shows up in the debug console window.
However, after hitting a breakpoint set at print("Break here") and manually entering the command cProfile.run("10 + 10") into the debug console window, I get the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.8/cProfile.py", line 16, in run
return _pyprofile._Utils(Profile).run(statement, filename, sort)
File "/usr/lib/python3.8/profile.py", line 57, in run
self._show(prof, filename, sort)
File "/usr/lib/python3.8/profile.py", line 72, in _show
prof.print_stats(sort)
File "/usr/lib/python3.8/cProfile.py", line 42, in print_stats
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
File "/usr/lib/python3.8/pstats.py", line 96, in __init__
self.init(arg)
File "/usr/lib/python3.8/pstats.py", line 110, in init
self.load_stats(arg)
File "/usr/lib/python3.8/pstats.py", line 136, in load_stats
raise TypeError("Cannot create or construct a %r object from %r"
TypeError: Cannot create or construct a <class 'pstats.Stats'> object from <cProfile.Profile object at 0x7efee11c30a0>
I am also able to run cProfile.run("10 + 10") in a command line python session as well as in the VSCode terminal ("integratedTerminal").
Any ideas on how to fix this and why the behavior is different for the debug console window?
I tried searching information regarding the mechanisms of the debug window in comparison with terminal window but have not found anything of substance yet.
Related
I am trying to use pyinstaller to create a .exe for someone else to run. The program uses mysql to ping a sql database and return information from it. When I run the program in PyCharm and with pyinstaller --onedir, everything works fine. However, when I bundle the program with --onefile, I get this error and traceback when running:
Traceback (most recent call last):
File "main.py", line 266, in <module>
File "main.py", line 88, in main
File "main.py", line 108, in grabData
File "sql.py", line 12, in SQLconnect
File "mysql\connector\pooling.py", line 286, in connect
File "mysql\connector\connection_cext.py", line 101, in __init__
File "mysql\connector\abstracts.py", line 1095, in connect
File "mysql\connector\connection_cext.py", line 199, in _open_connection
TypeError: argument 6 must be str, not None
For reference, here is the relevant line in the _open_connection function call in connection_cext.py:
self._cmysql = _mysql_connector.MySQL(
buffered=self._buffered,
raw=self._raw,
charset_name=charset_name,
connection_timeout=(self._connection_timeout or 0),
use_unicode=self._use_unicode,
auth_plugin=self._auth_plugin,
plugin_dir=self._plugin_dir,
)
The __init__ of this file has this code snippet:
self._plugin_dir = os.path.join(
os.path.dirname(os.path.abspath(_mysql_connector.__file__)),
"mysql",
"vendor",
"plugin",
)
I believe this plugin directory is the reason my code is failing, but I do not know how to bypass this or set it so that it references the right file at runtime. I know pyinstaller creates a temp file at runtime, but I don't know how to get the module to use it as the plugin directory.
Any help would be greatly appreciated! I really really wanna keep it in --onefile mode for simplicity for the user, so any solutions that maintain that would be ideal. Thanks!
If I go on cmd and write python -m idlelib, that would open IDLE. If I were to then go on configure IDLE, on the cmd, it gives be an error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\editor.py", line 574, in config_dialog
configdialog.ConfigDialog(self.top,'Settings')
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 78, in __init__
self.create_widgets()
File "C:\Users\\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 113, in create_widgets
self.highpage = HighPage(note)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 693, in __init__
self.load_theme_cfg()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 998, in load_theme_cfg
self.paint_theme_sample()
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\idlelib\configdialog.py", line 1279, in paint_theme_sample
self.highlight_sample.tag_config(element, **colors)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3854, in tag_configure
return self._configure(('tag', 'configure', tagName), cnf, kw)
File "C:\Users\xxx\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1627, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid color name "#00224"
I probably have a custom theme with an invalid color, however, how am I supposed to delete it if I can't access it (since it crashes when I do so).
There was a post, Python freezes when configuring IDLE that had I believe the same issue, but all he says as a solution is "manually deleting the faulty theme", which he doesn't explain. Pretty much, I want to access configure IDLE option without it crashing. Once it does crash, the only way I can close it then is by using task manager or restarting my computer.
As solution, you can tell me how to delete a custom theme without using IDLE if that's possible.
If the problem is in a custom theme, then the user configuration file you need to edit is $HOME/.idlerc/config-highlight.cfg. In your case, $HOME, based on the url below, appears to be C:/Users/chess. Just add a digit to make six. You can use the IDLE editor to do so. You should then be able to edit the color properly in the config dialog.
The problem might possibly be a character missing from the defaults file supplied with IDLE:
C:\Users\chess\AppData\Local\Programs\Python\Python38-32\lib\idlelib\config-highlight.def
Thank you for opening IDLE in a console, getting the traceback, and posting all of it. It gave me an idea of how to prevent the crash, so I opened a bug report
I have Asterisk 13.20 set up and running fine on Ubuntu 16.04,calls are going well through a Softphone(Zoiper), I came across a Library in Python "Pycall" which lets you make calls through a Python Script.So I tried testing a snippet from the site Pycall
The code that I used:
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
Just made changes in the extension,wherein I used one from my server
However I am getting the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
c.spool()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 131, in spool
self.writefile()
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 119, in writefile
f.write(self.contents)
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 114, in contents
return '\n'.join(self.buildfile())
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
raise ValidationError
pycall.errors.ValidationError
Tried searching online for the solution but coudnt find one,What am I doing wrong?
This question not related to PBX, it is just incorrect use of LIB.
General instruction how to solve ANY issue with availible source code.
You have error
File "/usr/local/lib/python2.7/dist-packages/pycall/callfile.py", line 96, in buildfile
Go that file and line, check code, add more debug if needed, fix your app.
Run as asterisk user.
sudo su asterisk -s /bin/bash
python
from pycall import CallFile, Call, Application
call = Call('SIP/flowroute/18882223333')
action = Application('Playback', 'hello-world')
c = CallFile(call, action)
c.spool()
I am currently having problem running python programs in pycharm, I generally used to right click and run the program. I want to run the program like this:
python hrllo.py rahulkapoo vit university
Here is the error I get:
Traceback (most recent call last):
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 107, in <module>
aggregate()
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 88, in aggregate
br = login()
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 23, in login
response = br.open('https://academics.vit.ac.in/student/stud_login.asp')
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 255, in _mech_open
raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt
Process finished with exit code 1
In PyCharm, right-click on the script (or within the editor window that has the script open, click Create 'scriptname', put your params in the Script Parameters box near the top and click OK.
The new run config will appear to the left of the run button at the top of Pycharm (at least in my version it does). Now make sure that the new run config is listed when running the script.
I have recently re-installed spyder on ubuntu 12.04. Here is the problem:
When I type an opening bracket in the console, the focus switches immediately to the internal console, displaying an error (that I interpret as "missing closing bracket"?) While I appreciate the code monitoring, it would be nice if the console let me finish my line of code first before jumping to conclusions.
How can I avoid this behavior? (I dont mind the "error" showing in the internal console, but the switch to the internal console whenever I open a bracket is quite disruptive.)
Here is the output of the internal console:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/shell.py", line 298, in keyPressEvent
self.postprocess_keyevent(event)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/shell.py", line 727, in postprocess_keyevent
ShellBaseWidget.postprocess_keyevent(self, event)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/shell.py", line 438, in postprocess_keyevent
self._key_parenleft(text)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/shell.py", line 797, in _key_parenleft
self.show_object_info(last_obj, call=True)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/mixins.py", line 608, in show_object_info
signature=True, color='#2D62FF')
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/mixins.py", line 108, in show_calltip
self.calltip_widget.show_tip(point, tiptext, wrapped_textlines)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/calltip.py", line 157, in show_tip
forward=False)
File "/usr/local/lib/python2.7/dist-packages/spyder-2.3.0-py2.7.egg/spyderlib/widgets/calltip.py", line 252, in _find_parenthesis
while category(char) != 'Cc' and position > 0:
TypeError: need a single Unicode character as parameter
To not show errors on the Internal console, you need to go to
Tools > Preferences > General > Debugging
and deactivate the option called
[ ] Pop up internal console when internal errors appear