(In Windows 10, I have installed ...\AppData\Local\Enthought\Canopy
that includes Python 2.7
, and another ...\AppData\Local\Programs\Python\Python35
that includes Python 3.5
. %PATH
points to Canopy)
I want to make "attaching the PyDev interactive debugger to Python code running in PyXLL" work by following this link and this link.
So I have done the following:
saved eclipse_debug.py
in the folder ...\AppData\Local\Enthought\Canopy\User\Lib\site-packages\pyxll\examples\
, and made pyxll.cfg
include eclipse_debug.py
added eclipse/plugins/org.python.pydev_4.5.4.201601292234/pysrc
to %PATH
(echo %PATH
does show this path, whereas echo %PYTHONPATH%
still returns %PYTHONPATH%
in a command prompt)
added import pydevd;pydevd.settrace()
to the hello
function, which worked before in Excel (hello("abc")
did return Hello, abc
).
reloaded PyXll in Excel
However, as a result,
hello
function does not work anymore
there is no new menu item as promised by This module adds an Excel menu item to attach to the PyDev debugger, and also an Excel macro so that this script can be run outside of Excel and call PyXLL to attach to the PyDev debugger.
Therefore, I don't know how to debug.
Could anyone help?
PS: my quess is that pvdevd
is not well inserted in the environment, because when I type import
in the code, pydevd
is not automatically suggested as packages such as numpy
or numbers
. But I am really confused with controlling PYTHONPATH
or PATH
inside Eclipse.
Edit 1:
I have set PYTHONPATH
in the control panel of Windows to be ...eclipse/plugins/org.python.pydev_4.5.4.201601292234/pysrc
. As a result, echo %PYTHONPATH%
still returns this path in a command prompt. And the pydevd
is auto-completing in eclipse.
With the following code, without using eclipse_debug.py
, and after launching debug server
, the execution breaks just after the line of settrace
:
from pyxll import xl_func
@xl_func("string name: string")
def hello(name):
import pydevd;pydevd.settrace()
return "Hello, %s" % name
Now, I want to follow the way of eclipse_debug.py
. I have done the following:
1) erase PYTHONPATH
in the control panel of Windows (so, I want to rely on eclipse_debug.py
to find the path)
2) modify only the first line of eclipse_debug.py to be eclipse_roots = [r"C:\my_path_to\eclipse"]
.
3) add eclipse_debug.py
to pyxll.cfg
4) use the following code to define the function hello
:
from pyxll import xl_func
@xl_func("string name: string")
def hello(name):
return "Hello, %s" % name
5) launch debug server
of eclipse, and then launch Excel, and then reload PyXLL
However, no menu item about debug appears in Excel, although the hello
function works in Excel. Is there something wrong about my approach?
Rather than modifying the PYTHONPATH
or PATH
at the environment level, simply do import sys;sys.path.add(r'< full path to>eclipse/plugins/org.python.pydev_4.5.4.201601292234/pysrc')
above the import pydevd;pydevd.settrace()
So you should end up with:
import sys
sys.path.add(r'< full path to>eclipse/plugins/org.python.pydev_4.5.4.201601292234/pysrc')
import pydevd
pydevd.settrace()
To answer some of your related issues:
PATH
for python modules. That is what PYTHONPATH
is for. At start-up Python will set sys.path
to the contents of PYTHONPATH
+ any other settings. pydevd
not auto-completing was most likely because you PyDev does not know about the modifications you made or intended to make to PYTHONPATH
. You can tell PyDev by modifying the interpreter settings.eclipse_debug.py
is intended to ease the connection to the debugger. You should use the eclipse_debug.py
method or the above method. However if you use eclipse_debug.py
you must update the paths near the top of the file.