I would like to add a breakpoint to a pydev project. I am using eclipse with the pydev plugin. I am running Windows 7. The file I want to debug is located at C:\cygwin\workspace\project\main.py .
When I attempt to add the breakpoint by double-clicking to the left of the line on which I want the breakpoint, the breakpoint appears to be visually present in the file, but then I get this error when I click debug:
pydev debugger: warning: trying to add breakpoint to file that does not exist: /workspace/project/C:\cygwin\workspace\project\main.py
Note that the file still appears to run fine both in debug and normal run modes. I can also run the file outside the ide by running python main.py.
I was actually able to get this working. I realize I'm using PyCharm, but the solution should be easily adapted since they both use PyDev. The basic problem is that the IDE is expecting windows paths while PyDev is expecting cygwin paths. I found the appropriate places in PyDev to do those conversions.
Here's my setup
configure your project to use a python for cygwin binary (this may not be necessary)
edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd.py. This converts the paths sent to the debugger to cygwin paths. Around line 597, where file = NormFileToServer(file) is located, make the following changes
orig_file = file
file = NormFileToServer(file)
if not os.path.exists(file):
file = orig_file.replace('c:/cygwin','')
file = file.replace('\\','/')
file = file.replace(' ','\ ')
file = NormFileToServer(file)
if not os.path.exists(file):
sys.stderr.write('pydev debugger: warning: trying to add breakpoint'\
' to file that does not exist: %s (will have no effect)\n' % (file,))
sys.stderr.flush()
do the same filename conversion a few lines later under the elif cmd_id == CMD_REMOVE_BREAK statement
edit Program Files/JetBrains/PyCharm 2.5/helpers/pydev/pydevd_comm.py. This converts paths sent back to pycharm into windows paths. Around line 549 alter the code to look like this:
myFile = pydevd_file_utils.NormFileToClient(curFrame.f_code.co_filename)
myFile = "C:\cygwin" + myFile
myFile = myFile.replace('/','\\')
Adjust the paths as needed. The big thing that helped me figure this out was to add PYCHARM_DEBUG=True in the environment variables of the PyCharm run/debug configurations.
Hope this saves someone else the 6 hours I spent figuring this out!
Cygwin is not really properly supported in PyDev, thus, you either must work on windows using a python windows distribution or you must work on Linux using a python for linux...
The real issue is that the paths must be translated back and forth at each step when inside cygwin (to make the communication with the IDE)... some initial work has been done on that front, but it didn't go forward...
One approach I didn't really attempt but which could work could be trying to use all within cygwin (i.e.: use PyDev running inside cygwin too: the linux version of java/eclipse/pydev -- not only the python interpreter, that way both would see paths in the same way), but I haven't really tested that setup, so, I'm not 100% certain it'll work.
pydev debugger: warning: trying to add breakpoint to file that does not exist: /vagrant/pytest/C:\Program Files\Git\vagrant\vagrant\pytest\remote.py (will have no effect)
The above error is keeping on occuring to me. I am using eclipse with pydev installed.
INitiualy I configured the PATHS_FROM_ECLIPSE_TO_PYTHON value wrongly but then updated it. But the updated value is not reflecting in the above error but shows old value only.
How to flush the old configurtion PATHS_FROM_ECLIPSE_TO_PYTHON and make the latest value used when executing the file
Related
I am currently learning to code with python in vscode but recently I have been having problems with file seemingly deleting themselves after attempted execution (image 1). I have tried Ctrl+z and I have tried recovering them but neither have worked. The files are not in my recycling bin either. If I try to create a new file of the same name in the same folder it shows me a error message (image 2) of "unable to resolve non-existing files"
When I execute my code the file saves but then becomes deleted:
This message appears if I try to undo the delete:
Have you tried to restart vscode? It is recommended that you could try the following aspects:
Check if there is any effect caused by the related expansion. For example, LaTeX Workshop extension has the function of cleaning generated files.
Check your setting.json Files,clear the contents of the user setting.json file and the vs code will return to the default value.
If it still doesn't work, you could consider installing vscode again.
Try running the Python file through a command prompt or terminal using the command python <foo_file_name>. Doing this will either confirm or deny the theory that #jasonharper made in the comments.
If you can run the script that way then we know that #jasonharper was correct and somehow your execute button/command was tampered with.
I had a similar issue using a different programming language. Building generated a file that got deleted automatically.
In my case the Windows 10 default antivirus was the cause. Turned off real-time scanning, tried again and then my files weren't deleted.
Adding an exception for the folder fixed it.
I had the Same problem with a PHP file, and turns out it wasn´t VS CODE. It was my antivirus that was moving the file to quarentine!!
I am remote debugging python on a raspberry pi from a windows 10 PC running Eclipse. I am able to write and execute python scripts remotely. SSH is working fine and I am able to start a debugging session without any problem. However, when attempting to debug I keep getting the error
I am attempting to set the remote path in the file simpleTest.py below. This has worked previously. However, for some reason the old settings appear to be getting confused with the attempt to set the remote path.
import pydevd
from pydevd_file_utils import setup_client_server_paths
MY_PATHS_FROM_ECLIPSE_TO_PYTHON = [ ('C:\\Users\\baff6\\workspace\\RemoteSystemsTempFiles\\192.168.1.20\\home\\pi\\', ''), ]
setup_client_server_paths(MY_PATHS_FROM_ECLIPSE_TO_PYTHON)
pydevd.settrace('192.168.1.10', port=5678)
a=1
print( a )
Previously I was remotely debugging a file called mpsTest2 on a different raspberry pi. However, I am no longer working on this file even though Eclipse seems to be trying to find this file in the folder that contains the file that I am working on (in this case simpleTest2.py).
I have no idea where the references to this other file are but I presume they exist in some configuration setting in Eclipse. However, I have looked everywhere and cannot find anything.
Any help in tracking down these settings would be much appreciated assuming I have not missed something very basic in the setup procedure I am following.
Best wishes, John
I probably should have done this first but eventually found that uninstalling PyDev from Eclipse and reinstalling solved the problem. This removed the old references and I was able to remotely debug without any problems. I assume it is possible to achieve this end result without having to perform the uninstall/install but am not sure how to do this.
I'm following a pretty old guide where one could tell PyDev a script path from another application & it would debug it, line by line in eclipse. I like this method, instead of putting settrace() breakpoints in the main script.
scriptpath = "Users/me/Desktop/script.py"
debuggerpath = "/Users/me/.p2/pool/plugins/org.python.pydev.core_7.5.0.202001101138/pysrc"
import pydev_debug as pydevd
pydevd.debug(scriptpath, debuggerpath, trace=True )
Most likely, the api has changed. What is the current method to do the same ?
Well, I'm not sure which guide is this (I don't think there ever was a pydev_debug in PyDev).
What that module probably did is add pydevd to sys.path and then setup the current tracing in using pydevd.settrace and then called execfile (in Python 2 -- for Python 3 the exec is a bit more contrived... see: https://github.com/fabioz/PyDev.Debugger/blob/master/_pydev_imps/_pydev_execfile.py)
So, although there's no ready made solution for that, it should be relatively easy to do with the building blocks provided by PyDev.
The contents of the file a.py are:
a = input()
print(a)
and fearless.txt contains the string : pink floyd.
Now, when I simply type in %a.py < fearless.txt at the command prompt (windows), it gives an error "lost.stdin".
However, when I type %python a.py < fearless.txt, no error occurs.
I don't understand this, given that .py is a recognized extension and is run by python. Shouldn't then, both be equivalent?
Note I'm using the symbol % in place of the actual directory.
( Python version : 3.4.3:9b73f1c3e601 and winXP-32 bit. )
It depends a bit on how the .py files are registered. It should work when the py.exe launcher is set up correctly. You can verify this by looking up the following key in the registry: HKEY_CLASSES_ROOT\Python.File\shell\open\command. The default value should be "C:\WINDOWS\py.exe" "%1" %*.
You can also try using the following instead:
type fearless.txt | a.py
I just noticed that you are using Windows XP. The problem you are seeing might be because of an old Windows bug with redirection. It was said to be fixed at some point, but maybe XP was still partially affected. I suggest you to update your system anyway because Windows XP is no longer supported by Microsoft.
If this is on a Unix system (as I'm guessing it is), you'll need to have a shebang line at the top of the file to tell the kernel that this is a file whose contents need to be executed by the specified interpreter. The .py extension is just a detail and is not used to decide "how to run" the given program.
When you try to run the file without the shebang, it's being executed by your current shell and that's what's giving you the errors. Python doesn't even come into the picture.
I have several python scripts which work just fine but one script has (as of this morning) started giving me this error if I try to run it from the bash:
: No such file or directory
I am able to run the 'broken' script by doing python script_name.py and after looking around a bit the general idea that I picked up was that maybe my line ending of the hashbang got changed (silently) so I looked at the line ending of a working script and a broken script via the :set list option in VI as indicated in this question -> View line-endings in a text file
Both files appear to end using the same character (a $) so I am kind of at a loss on how to proceed from here. Specifically, how to actually 'see' the line ending in case the set list was not the right method.
PS: The script is executable and the shebang is in there, I stated that it's just this 1 script that was working fine before the weekend but it started giving me this error as of this morning.
-- edit: --
Running the script through dos2unix does get it working again but I would like to know of any way to visualize the line ending somehow in VI(M) or why Geany somehow converted the line endings in the first place (as I never work on a dos/windows system anyhow).
From the comments above it looks like you have dos line endings, and so the hashbang line is not properly processed.
Line ending style are not shown with :set list in Vim because that option is only used when reading/writing the file. In memory line endings are always that, line-endings. The line ending style used for a file is kept in a Vim per-file option, weirdly called fileformat.
To see/change the line ending style from Vim, you can use the following commands:
:set fileformat
:set ff
It will show dos or unix. You want unix, of course ;-).
To change it quickly you can save the file with:
:w ++ff=unix
Or if you prefer:
:set ff=unix
And then save the file normally.
So see all the gory details just do :help fileformat, :help file-formats and :help fileformats
You can also use the dos2unix command to convert the file format
dos2unix
This helped me to run the python scripts
This normally happens when we open files in windows do changes and save it.
if you open the file locate the ^M characters at the end of every line
Thanks
Personally, I find it kinda wrong using direct path to python interpreter. As you dont use windows platform, you should have program env, usually in /usr/bin (/usr/bin/env). Try using following shebang:
#!/usr/bin/env python
Different distros store python binary in /bin or /usr/bin (or some weird locations), and this one makes your script config-independent (as far as possible, here we have possibility that env is stored elsewhere; still - it is less possible that env is not in /usr/bin than that python is mislocated).
I had similiar problem (if not exactly the same) and that worked for me.
Also, I have both python interpreters (2.7.x and 3.x) installed, so I need to use "python3" argument for env. AFAIR usually distros link different names to different binaries, so "env python" will run python2.7 on my system, "env python3" (also python33, or smth like that) will run p3k, and "env python2" (also python27, etc) will run python 2.7.x. Declaring which version of interpreter should be used seems like a good idea too.
I came across this problem editing my code on Windows, checking it in with git, and checking out and running it on Linux.
My solution was: tell git to Do The Right Thing. I issued this command on the Windows box:
git config --global core.autocrlf true
Modified the files and checked them in; voila, no such problem any more.
As discussed on the Git documentation.