Is it possible to set breakpoints in PyDev Scripting? - debugging

I would like to set a breakpoint in a PyDev script written in Jython. I've tried various configurations:
(1) Setting a breakpoint in the Eclipse editor but nothing happens.
(2 & 3) Forcing a trace by adding following code into the script:
import template_helper
if False:
py_context_type = org.python.pydev.editor.templates.PyContextType
def MyFunc(context):
# option (2) - try pydevd with another eclipse session hosting debug server
#import sys
#sys.path.append(r"... pydev.core_6.3.3.201805051638\pysrc")
#import pydevd; pydevd.settrace()
# option (3) - try pdb
import pdb; pdb.set_trace()
return "some text"
template_helper.AddTemplateVariable(py_context_type, 'mysub', 'A desc', MyFunc)
Trying pydevd (option 2) just crashes with an exception added to error_log along lines of:
Caused by: Traceback (most recent call last):
File "...\org.python.pydev.jython_6.3.3.201805051638\jysrc\template_helper.py", line 20, in resolveAll
ret = self._callable(context)
File "...\pydev_scripts\src\pytemplate_local.py", line 12, in MyFunc
import pydevd; pydevd.settrace(stdoutToServer=True, stderrToServer=True)
File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 1189, in settrace
_locked_settrace(
File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 1295, in _locked_settrace
debugger.set_tracing_for_untraced_contexts(ignore_frame=get_frame(), overwrite_prev_trace=overwrite_prev_trace)
File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 595, in set_tracing_for_untraced_contexts
for frame in additional_info.iter_frames(t):
File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydevd_bundle\pydevd_additional_thread_info_regular.py", line 117, in iter_frames
current_frames = _current_frames()
File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydevd_bundle\pydevd_additional_thread_info_regular.py", line 26, in _current_frames
as_array = thread_states.entrySet().toArray()
AttributeError: 'java.lang.ThreadLocal' object has no attribute 'entrySet'
Trying vanilla pdb (option 3) prints the (Pdb) prompt in the PyDev Scripting console but one can't enter any text and go into interactive mode, eg:
(Pdb) IOError: IOError(...nvalid',)
> ...\org.python.pydev.jython_6.3.3.201805051638\jysrc\template_helper.py(20)resolveAll()
-> ret = self._callable(context)
(Pdb)
Perhaps it's not possible. Any suggestions?

For future reference, I was eventually able to debug scripts by downloading jython 2.7.1 installer from maven. I then installed this jython to a temporary location. After backing up the jython plugin folder bundled with pydev, I copied and pasted the relevant directories over the pydev jython installer along with a copy of pydevd package. I was able to step through debug in separate instance of Eclipse after setting a breakpoint as described in my Option (2) above.
Thanks for your help in the comments #FabioZadrozny.

Related

how to resolve anaconda packages installation problem like 'KeyError:pkgs_dirs'?

when i install a package in old venv,as below:
(conda_venv)my-ubuntu:~/file$: conda install random
Collecting package metadata (current_repodata.json):failed
Traceback (most recent call last):
File"/home/my/anaconda3/lib/python3.9/site-packages/conda/exceptions.py",line 1214, in print_unexpected_error_report message builder.append(get main info str(error report['conda info']))
File"/home/my/anaconda3/ib/python3.9/site-packages/conda/cli/main_info.py", line 237, in get_main_info_str
info dict[' '+ key] = ('\n’ + 26 *'').join(info dict[key])
KeyError: 'pkgs_dirs'
and
enviroment variables:
conda info could not be constucted.
KeyError('pkgs_dirs')
and when i create a new venv,it shows the same error as above.
I found someone had the same prolem like me and they used "conda config --show-sources" to resolve,and i tried,but i got nothing but a blank line.
And i also tried "conda info",it showed
File"/home/my/anaconda3/lib/python3.9/site-packages/conda/exceptions.py", line 1082, in __call return func(*args,**kwargs)
File "/home/my/anaconda3/lib/python3.9/site-packages/conda/cli/main.py", line 87, in _main exit code = do call(args,p)
...
...
File "/home/my/anaconda3/lib/python3.9/site-packages/conda/ vendor/distro.py". line 599. in init
self. lsb release info = self. get lsb release info() \
subprocess.CalledProcessError:Command 'lsb_release -a' returned non-zero exit status 126
i don't know how to handle with this problem.I will appreciated it if any one can help.Thanks in advance!
Issues with KeyError can result from malformed configuration files. Please check your .condarc files are not corrupted (should be valid YAML). These can be located in three locations:
user home (~/.condarc)
Conda environment prefix (e.g., /home/my/anaconda3/.condarc, for OP)
working directory
It also should be noted that it appears to be looking for a key pkgs dirs rather than the standard pkgs_dirs. Perhaps someone ran a conda config --set 'pkgs dirs' '/path/to/blah' by mistake?

cqlsh will not run on OS X

I installed Cassandra on Big Sur 11.4 using homebrew, and when I tried to run cqlsh, I received this error.
isaackim#Isaacs-MacBook-Pro bin % cqlsh
Traceback (most recent call last):
File "/usr/local/Cellar/cassandra/3.11.10/libexec/bin/cqlsh.py", line 2458, in <module>
main(*read_options(sys.argv[1:], os.environ))
File "/usr/local/Cellar/cassandra/3.11.10/libexec/bin/cqlsh.py", line 2232, in read_options
configs.read(CONFIG_FILE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py", line 305, in read
self._read(fp, filename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ConfigParser.py", line 512, in _read
raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
I previously had Anaconda3 installed, and received the same error (the only difference was the path to cqlsh.py). I thought it might be an issue with Anaconda so I uninstalled Anaconda entirely, then I reinstalled Cassandra using homebrew.
I would appreciate any and all suggestions. Thanks in advance.
Thanks to Alex Ott's suggestion, I managed to replicate the issue you posted by creating a bad ~/.cassandra/cqlshrc configuration file which only contains the following line:
username = alice
As this error suggests:
ConfigParser.MissingSectionHeaderError: File contains no section headers.
the configuration parser detected that there are no section headers in the file. Section headers are line entries enclosed in square brackets ([header_name]). For example:
[authentication]
username = alice
password = Som3Comp7exPa$$word
Review your cqlshrc and make the necessary corrections. If necessary, use the example cqlshrc.sample file in conf/. Cheers!

web application using dash in python

I have develop a simple program using dash plotly in spyder but it showing me the following error.
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(
html.H1(children='Hello Dash')
)
if __name__ == '__main__':
app.run_server(debug=True)
but it showing me the following error.
Running on http://127.0.0.1:8050/
Debugger PIN: 870-923-677
Traceback (most recent call last):
File "<ipython-input-13-3c5b23764cd8>", line 5, in <module>
app.run_server(debug=True)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\dash\dash.py", line 1503, in run_server
self.server.run(port=port, debug=debug, **flask_run_options)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\flask\app.py", line 938, in run
cli.show_server_banner(self.env, self.debug, self.name, False)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\flask\cli.py", line 629, in show_server_banner
click.echo(message)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\click\utils.py", line 259, in echo
file.write(message)
UnsupportedOperation: not writable
Spyder has some conflicts using Debug=True. Please run your code inside Visual Studio Code.
For my system: Your code is running fine.
Please tell us if this software swap solved your problem. If not, I will provide further assistance. :)

umap collectstatic gives "No such file or directory" error

As I have very little knowledge about Linux, pretty much all I can do is copy and paste things from a good tutorial and in most cases simply hope nothing goes wrong. I really tried finding a solution on my own and searching the internet but to no avail (I found a number of quite similar things but no solution I understood enough to be able to adapt it on my own to fix my problem).
I've installed an osm tile server using this amazing tutorial and it works like a charm. Now I want to install umap, using this tutorial.
Everything works fine until I get to the line "umap collectstatic". The error I get is this:
(venv) $ sudo umap collectstatic
[sudo] Passwort für umap2:
You have requested to collect static files at the destination
location as specified in your settings:
/home/ybon/.virtualenvs/umap/var/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "/usr/local/bin/umap", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/umap/bin/__init__.py", line 12, in main
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 193, in handle
collected = self.collect()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 115, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 112, in list
for path in utils.get_files(storage, ignore_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 399, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/home/ybon/Code/js/Leaflet.Storage'
Now, I get the something might be wrong with a setting in a config file somewhere, but changing the directory in local.py
doesn't seem to do anything (like I have set it to STATIC_ROOT = '/home/xxx_myusername_xxx/umap/var/static') - I have no idea where this "/home/ybon/Code/..." path even comes from! What settings ?
I sure didn't specify THIS path anywhere! And the folder is indeed nowhere to be found on my machine. Maybe using virtualenv is somehow generating it, and I can't find it on my machine because it IS virtual (as in "not really there physically") but this is just a very wild guess and I don't really know what I'm talking about.
(I tried running the command with and without sudo and it doesn't change anything).
I have always wanted to install a tile server and have tried the tutorials you have given today. So I'm a learner like you!
Installing the Tile Server with the tutorial https://www.linuxbabe.com/linux-server/openstreetmap-tile-server-ubuntu-16-04 was really straightforward. I only used the part for Rhineland Palatinate.
With Umap (https://umap-project.readthedocs.io/en/latest/ubuntu/#tutorial) I had some problems.
1. A port was used twice. I changed the port for Apache.
2. After creating the local configuration (wget https://raw.githubusercontent.com/umap-project/umap/master/umap/settings/local.py.sample -O /etc/umap/umap.conf) this file was not immediately recognized. I helped myself by changing the file before executing the command "umap migrate".
I have made the following changes:
# For static deployment
STATIC_ROOT = '/etc/umap/var/static'
# For users' statics (geojson mainly)
MEDIA_ROOT = '/etc/umap/umap/var/data'
# Umap Settings
UMAP_SETTINGS='/etc/umap/umap.conf'
STATIC_ROOT und MEDIA_ROOT I have changed, because so the user umap has all permissions. Then I set the envirement variable UMAP_SETTINGS because otherwise the settings file /etc/umap/umap.conf is not found.
( I also have no idea where this "/home/ybon/Code/..." path comes from. After the configuration file is properly loaded, the path is loaded from the configuration file. That's why that's not important anymore. )
Now I could use the following commands without errors:
(venv) $ umap collectstatic
Loaded local config from /etc/umap/umap.conf
You have requested to collect static files at the destination
location as specified in your settings:
/etc/umap/var/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying '/srv/umap/venv/lib/python3.5/site-packages/umap/static/favicon.ico'
...
290 static files copied to '/etc/umap/var/static'.
(venv) $ umap storagei18n
Loaded local config from /etc/umap/umap.conf
Processing English
Found file /etc/umap/var/static/storage/src/locale/en.json
Exporting to /etc/umap/var/static/storage/src/locale/en.js
..
Processing Deutsch
Found file /etc/umap/var/static/storage/src/locale/de.json
..
Found file /etc/umap/var/static/storage/src/locale/sk_SK.json
Exporting to /etc/umap/var/static/storage/src/locale/sk_SK.js
(venv) $ umap createsuperuser
Loaded local config from /etc/umap/umap.conf
Username (leave blank to use 'umap'):
Email address:
Password:
Password (again):
Superuser created successfully.
(venv) $ umap runserver 0.0.0.0:8000
Loaded local config from /etc/umap/umap.conf
Loaded local config from /etc/umap/umap.conf
Performing system checks...
System check identified no issues (0 silenced).
April 09, 2018 - 14:02:15
Django version 1.10.5, using settings 'umap.settings'
Starting development server at http://0.0.0.0:8000/
And finally I was able to use umap.

Python web scraping stopped working - Invalid File Error

I have been working on a web scraping program and it has recently just stopped working and is giving me the following error.
Traceback (most recent call last):
File "C:/Users/Bob/Desktop/test 3.5.py", line 7, in <module>
with open(saveDB,'rb') as f:
TypeError: invalid file: WindowsPath('Z:/project1/MasterWellDB.txt')
Where Z: is a network drive, but I have also moved the file locally and the error still exists.
I have tried multiple python versions, uninstalled and reinstalled visual studio multiple times and I am still clueless.
Here is my code:
from pathlib import Path
import pickle
# Opening well database
saveDB = Path(r"Z:\project1\MasterWellDB.txt")
#open picked DB if avaiable else remake database
if saveDB.exists():
with open(saveDB,'rb') as f:
wells = pickle.load(f)
print('success!')
Any help would be greatly appreciated. Thanks!

Resources