0

When using python packaged as embeddable zip file somewhere on a share and my python apps (there are multiple ones) somewhere else on separate shares I can version the apps separated from each other and from python. The apps then "share" (use) the same python version (embeddable instance) - so I only have to manage one python version for all of my apps.

Now I want do debug one app. (Assuming here: The app already works without errors when running it) I use eclipse and PyDev. After workspace creation and linking the code as folder into a project in the eclipse workspace I tell PyDev where to find my python embeddable interpreter and which app to launch.

When I start debugging the debugger tells me:

Traceback (most recent call last):
  File "C:\eclipse\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\pydevd.py", line 19, in <module>
    from _pydev_bundle import fix_getpass
ModuleNotFoundError: No module named '_pydev_bundle'

So the debugger doesn't find ist own modules? Now I add the path of the PyDev sources to the PYTHONPATH of the embeddable python interpreter in the file

python36._pth

as follows:

C:\eclipse\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc

(Yeah that path is not relative) (Side note: I have to reconfigure the interpreter in eclipse to make pydev recognize the path changes)

Doing so resolves that problem and I can debug the app. (Ignoring warnings of the debugger that flood my console)

Can someone tell me why I need to add that path to my python embeddable which should be as independent as possible? Can I setup that somewhere else? I already tried to add the sources path to the eclipse project PYTHONPATH and the eclipse interpreter PYTHONPATH without success.

PS: My python should be independent of the apps to share it between them and to be able to exchange it (fresh upgrade to newer version). The apps are started using a Windows power shell link where I call my python embeddable executable and pass the app as an argument. So double clicking the power shell icon is enough for app users

1 Answer 1

0

I didn't really understand one thing: you're launching your code from within Eclipse (say debug as > Python) and it's giving that error?

Are you changing the PYTHONPATH somehow?

The way that it works is that Eclipse/PyDev will change the PYTHONPATH environment variable to add the needed paths for the pydevd debugger, but if you have a custom Python or zip which is then replacing or not using that var, that result would be expected and you have to make sure that the PYTHONPATH env var is still respected for the debugger to work...

Sign up to request clarification or add additional context in comments.

6 Comments

I'm calling it by debug as > Python yes.
I do Change the PYTHONPATH at runtime by calling sys.path.append What PYTHONPATH variable is used (env var?)? How can I check if the variable is not used or the path is replaced by either the zip file or my app? (I can check if it works with a hello world app - yes - I will do that)
I tested this with a Hello world app and it also doesn't work as long as I do not add the _pydev_bundle to the path file of the python embeddable zip file. So most likely the embeddable zip file doesn't use the PYTHONPATH variable - which makes sence, because the embeddable zip should be independent. If it would use the PYTHONPATH variable of the specific machine it is running on it would be machine dependent.
That fact is noted here: docs.python.org/3/using/windows.html "When extracted, the embedded distribution is (almost) fully isolated from the user’s system, including environment variables, system registry settings, and installed packages." I think that is the reason for the error from pydev. And therefore one has to add the pydev Debugger Environment to the embeddable zip file path. Do you raise any objections?
I agree... you have to do the sys.path.append yourself to add the debugger as that way of using Python doesn't use the PYTHONPATH environment variable.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.