PyDev Debugging - python

My interpreter is the python 2.6 interpreter that comes with cygwin.
I have a pydev project that contains a linked folder.
In the folder, due to outside constraints, I have two sub-folders, one with a bunch of scripts I develop, and one which serves as the run directory for all my run configurations.
When I run the project (not debug) everything works fine.
However, when I choose to debug the project, my custom modules aren't found, and the import fails.
I tried adding my scripts folder to PYTHONPATH, but that didn't help, and when I printed sys.path It contained weird stuff, all of the form:
<path to run directory>/<path to entry in PYTHONPATH>
I can't make heads or tails out of it.
I'll appreciate any help.

Unfortunately, that's a known issue. PyDev does not support Cygwin for debugging. The primary reason is that the paths that Python reports don't match the paths you configure in windows, so, a translation step would be needed for each path (even some other areas such as code-completion or code-analysis could have problems).
You can probably do this translation yourself at eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd_file_utils.py (instructions on the file), but note that this may be more work than it's worth (the recommended approach is using a native Python install on Windows instead of through cygwin) -- or if you need an interpreter on Linux, develop on Linux :)

Thanks, you made my day, its actually very easy,
you have to change the PATHS_FROM_ECLIPSE_TO_PYTHON variable inside pydevd_file_utils.py as,
PATHS_FROM_ECLIPSE_TO_PYTHON = [
(r'C:\Users\usernam\workspace-cpp\python-proj\src',
r'/cygdrive/c/Users/usernam/workspace-cpp/python-proj/src')
]
But this needs to be changed for all your own python source files you desire to debug

I am happy to announce a new release of ePyUnit, which solves the load-path issue of 'pydevd.py'. This works from within Eclipse/PyDev as well as from an arbitrary process started from the command line.
ePyUnit now includes the automation of remote debugging with PyDev and Eclipse by 'pydevd.py'. This works seamlessly for the 'subprocess' call as well as independently started command line processes.
See:
https://pypi.python.org/pypi/epyunit
https://pythonhosted.org/epyunit/
For basics of remote debugging:
http://www.pydev.org/manual_adv_remote_debugger.html
Also enhanced unittest integration into PyUnit.
Comments and fixes are welcome.
Have fun...

Related

Python Interpreter not showing anything in PyCharm

Issue
So, I've used PyCharm for quite a while and I know how to set environments, etc. For some reason, I can't seem to access the Python interpreters that I've got (see image).
When I open the same project in Clion I am able to run the files and I can see the interpreters.
Attempted solutions
Run in Clion to see if the interpreter "sticks".
Removed the .idea file.
Reinstalled PyCharm.
Usually Python Interpreter is a sub-item of Build, Execution, Deployment in the Settings. (In PyCharm 2021, the layout in PyCharm 2019 was slightly different).
The fact the item appears separately is a strong hint that you either installed a plugin or for some reason the IDE was opened in LigthEdit mode (this can easily happen if you launch the IDE using the command-line). This can also happen if you don't have an open project (having files open is not the same as opening a project, as such, with an .idea folder - the IDE configuration files will be different.)
Having the IDE in LightEdit mode provides only a limited set of functionalities, so the IDE doesn't allow you to configure an Interpreter in the usual way (other setting dialogues will also behave different from usual).
The solution is to Exit the LightEdit mode, opening your previous project or a new one by going to File > Open or File > New Project.

Shipping Interpreter with Python application

I am new to Python. Please excuse me if my question seems stupid. I have spent a lot of time before posting this.
When I searched for shipping python interpreter with the applications, I found solutions including installing separate applications, using third party modules, etc...
I was thinking of more direct approach: I first install python interpreter on my machine (windows). Then I ship the installed python interpreter (copy and paste the folder) with the pyc file of my application. And finally I create a simple batch program that executes the interpreter and running the pyc file. In this case, the user can simply run the application by simply running the batch program. I have tried it and it worked.
Although this solution seems the most obvious and the easiest one, I am in a doubt about it because I cannot find any one mentioning it. Is there anything wrong with my solution? I usually create desktop applications for windows.
Thanks in advance.
Make a virtual environment for you application and then run run the command python filename.py --onefile --windowed while still being in the virtual env. activated,

Force eclipse to reload Python modules

I have started a Eclipse PyDev project, and found out that BeautifulSoup was missing.
I installed it using easy_install, and now the scripts runs fine from the command line. Eclipse, however, still thinks that BeautifulSoup isn't installed, displaying an annoying error message and not supplying any introspection or auto complete.
How can I force Eclipse to reload the system's python package list?
You have to reconfigure the python interpreters. Normally the automatic configuration utility should discover everything by itself, but otherwise you can manually add/remove packages. Here's a screenshot of where the settings are located:
In the only occasion in which I can recall I needed to do that, all I did was to remove the python interpreter from the list and running the Auto Config procedure again, but it should also be possible to simply add a library (bottom half of the screenshot).
HTH!

How to debug SCons scripts using eclipse and pydev?

I'm a newbie to SCons and also using pydev. Can someone help me with instructions on how to debug scons scripts using Eclipse and pydev? Is it even possible considering the fact that SCons is a seperate app and not an extension to python?
You are right. Since the SCons is python based, the SCons scripts are debuggable via EClipse PyDev. For this, you need to do the following in the debug configuration...
1. Under the main tab, set the main module to the SCons file which will be available under the python/scripts directory if you have installed SCons. If you have not run the install of SCons you can point to this file under the SCons directory.
2. Under the arguments tab, set the working directory to the root of your project.
Now set the breakpoint either on SConstruct or SConcript and run in debug mode. That's all!!
With this approach you can not only debug your product code but also the build scripts that builds your product :-) Happy Debugging!!!!
I'm not an Eclipse expert, but since you didn't get any other answer...
If you make the SCons source a part of the Eclipse project, and run the whole command from within Eclipse it should work like any Eclipse debugging. SCons is written in Python, there is no reason it shouldn't be debuggable in Eclipse just like anything else.
if you are using SCons for C/C++ development and Eclipse CDT check out http://sconsolidator.com (within the next weeks), we will release our SCons Eclipse plug-in for free public use shortly. It also contains an "interactive mode" that allows SCons builds to run more quickly (no startup time) and also to debug SCons in a console. However, the tip with using PyDev still applies (can be installed alongside with CDT in the same Eclipse instance.
On MAC to debug scons through pydev follow Lennart's answer but with one simply addition.
Using Finder (or terminal) browse to where scons is installed. You can find this with the "which" command.
e.g. which scons
-> /usr/local/bin/scons
Make a copy of the scons file and call it scons.py.
Now when you create the Debug Configuration in Eclipse use scons.py as the "Main Module".
PS: To add a scons project to Eclipse I found it easier to use a "Linked Folder" pointing at /usr/local/bin/. i.e. Because I was getting a read-only error when trying to add the directory itself.
I've since gain more experience with SCons / Python and I'd recommend using python's pdb module. To use it simply add the following code to your SCons/Python files.
import pdb; pdb.set_trace()
When the file is run from the command line a breakpoint will be hit at this line. I also moved away from Eclipse. A lightweight editor will be just as good for Python development. I use Sublime.
As an addendum: on Windows, I had to copy the scons-installed files to reside under C:\Python27\Lib\site-packages\scons in order for this to work. Adding the original installed location, qualified with the version number, to the PYTHONPATH, did not work.

How to deploy Python to Windows users?

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.

Categories

Resources