How does one debug a module that is run as a script (with -m flag) from within PyDev? - pydev

I have a module that is part of a library I am writing. The library has multiple executables. These are run from the command line as a script with the syntax python3 -m mypackage.mysubpackage.MyModule
I am familiar with eclipse, its debugger and PyDev, but I have not found how to set a debug/run configuration to launch MyModule within PyDev.
I have tried to add -m or -m mypackage.mysubpackage.MyModule as VM arguments to python.exe within the Arguments section of the Debug Configuration, but this does not work even setting the appropriate working directory to have mypackage in the PYTHONPATH.
I know how to launch the program outside eclipse and connect it to eclipse using a debug server. I know I can also make a little auxiliary script that is not part of the library just to launch the program so I can run it inside eclipse, but I would prefer the convenience of being able to launch the module directly within eclipse itself and I feel PyDev should be able to do this.

If you just press F9 PyDev should launch your module.
Although note it'll launch the file directly. If you require it to be launched with the -m flag (so that your relative imports resolve in that file), you can configure it in the preference:
preferences > PyDev > Run > Launch modules with python -m ...
PyDev will compute the module name based on the file location and PYTHONPATH configured in this case.
p.s.: You may want to take a look at http://www.pydev.org/manual_101_run.html for more details on re-launching your module, unit-tests, etc.

Related

Shell script exporting Hadoop library classpath does not working

I am trying to develop Python client which interacts with Hadoop file system 3.3 using pyarrow package. My OS is CentOS 8 and IDE is Eclipse pydev. The sample code is simple.
from pyarrow import fs
hdfs = fs.HadoopFileSystem('localhost', 9000)
But the prerequisite command has to be executed for the successful python codes running. The command is
# export CLASSPATH=`$HADOOP_HOME/bin/hdfs classpath --glob`
Whenever I run Eclipse IDE, I have to execute the above export CLASSPATH command before Eclipse. To prevent this inconvenience and to automate the IDE configuration, I make the shell script file like below,
#! /bin/bash
export CLASSPATH=$(/usr/local/hadoop/bin/hdfs classpath --glob)
echo $CLASSPATH
When I execute this script, output messages from shell script are correct. But when I execute the Eclipse on the next line, the above pyarrow Python codes do not work successfully. I have no idea of this failure.
When I execute the export CLASSPATH command on the shell itself, the Python codes on Eclipse work correctly. But when I execute shell script, the Eclipse Python codes throws errors.
Update
I enter the [Run Configurations] menu and choose [Environment] tab. I click [Add] and input the below values onto [New Environment Variable] Dialog.
Name : CLASSPATH
Value : $(/usr/local/hadoop/bin/hdfs classpath --glob)
But my configuration is not correct, the same errors are still brought again.
I attach the image of my IDE configuration.
As mentioned in comments, in eclipe's "Run Configurations" menu, you need to add en environment variable entry for called CLASSPATH.
The value must be whatever the shell returns when you run this command:
/usr/local/hadoop/bin/hdfs classpath --glob
Don't try to put $(/usr/local/hadoop/bin/hdfs classpath --glob), it will be interpreted as a string an won't work.

Eclipse Pydev adding PYTHONPATH=../:. before running a pytest module

I am developing something in Python in Eclipse PyDev. Per the instructions from my assignment, I need to run this program like so:
PYTHONPATH=../:. python grade_analysis.py
However I am just running the program with the standard Run button and (no surprise) it's not working correctly. It is a unit test that claims it runs 0 tests.
Does anyone know how to run this specific file with that pythonpath in Eclipse PyDev? I've been playing with settings in the Run Configuration and no luck
You have to configure those paths to be source folders inside of PyDev (a source folder is the folder that should be in the PYTHONPATH).
See: http://www.pydev.org/manual_101_project_conf2.html for details.

Running ant through eclipse it doesn't find environment variables, but running ant through terminal is fine

When i run ant through Eclipse some targets build fine, but ones that need a specific environment variable i.e. SOME_SDK that i set in my .profile file won't work. Even if i try to echo out ${env.JAVA_HOME}, Ant through eclipse will just print out that string. But if i run ant through the terminal (i.e. ant sometarget), it will find JAVA_HOME and SOME_SDK and echo those paths out. Ive checked eclipse that it's pointing to the same ant that is in my environment path (/usr/share/java/ant-1.8.1). Any ideas?
Thanks
When you open a terminal, the environment variables in your .profile get loaded. When you start Eclipse via the windowing system it is not being run under your user account, so your .profile is not available to Eclipse at runtime.
At least that's the case on my linux machine and I'm guessing its the same on a Mac. I put the environment variables that Eclipse needs to see in the /etc/profile file, which gets loaded at system startup.
You can specify variables in your Ant run configuration (Run As > Ant Build... > Environment tab).
I'm thinking that the Eclipse IDE environment handling is a bit spoiled, at least in *nix environments. Although similar to Kevin's case, what I'm finding is that although I do create a separate run profile and -successfully - run the test/install goals (maven instead of ant here, but that's negligible noise), and specify the JAVA_HOME environment variable for that run profile, the project does not validate the POM file.
All I'm left with is two separate choices:
use the /etc/profile approach, or
Edit eclipse.ini file including the system property there.
I think the latter is a cleaner workaround since it affects a configuration file that is only for the problematic application after all. Nevertheless, Eclipse should use the variables found in the user's path and leave us at ease to produce :)
What you need to do is remove the java.exe from c:\Windows\System32.
The reason is, in your %PATH% environment variable, it includes c:\Windows\System32, which has a java.exe file. If you run c:> java -version from a command prompt, you'll see that the version you're running does not match the jdk version.
Once you've done this, you will need to add: %JAVA_HOME%/bin to the %PATH% environment variable, so you can execute the java.exe from the jdk when running apps. Be sure to restart any application (including the command prompt) before expecting it to pick up the change.
Add this line to ~/.bashrc (or you can use another profile file):
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
(Don't forget to run source ~/.bashrc)
If you run start-eclipse from the command line, all environment variables will be picked up. This way, you only need to maintain a single set of environment variables across both command-line and eclipse environments.
NOTE: Stolen from Chris Fegley's answer at Launch mac eclipse with environment variables set

How to install and configure the EclipseFP Haskell plugin for Eclipse?

Can somone who has done this tell me exactly what to do? The documentation is lacking and what is there is incomplete and incorrect.
I've got the plugin installed, and told it to usethe GHC installation that I have as part of the Haskell Platform but Run As.. only shows me Run GHCi session. According to the cheat sheet, I should see Haskell Application.
Also missing are instructions for where to find the hugs executable, and the Cabal installation that the Haskell Preferences seems to suggest I should have.
Can anyone point out what I've missed?
I'm a Haskell beginner, hence trying to get Eclipse set up so I can play with it...
It seems that currently there is no way to create a non-interactive launch configuration
via GUI. However, you can do that by manually editing config files. The following instructions work with Eclipse 3.5.2, EclipseFP 2.0.2:
Make sure there exists a GHCI configuration.
Close Eclipse.
Go to directory .metadata/.plugins/org.eclipse.debug.core/launches in the root of your workspace.
There should be a file named something like "Main (project src).launch". Copy it under whatever name you wish, for instance "Run Main.launch"
Open your copied file in a text editor and replace the option --interactive with -e main.
Save the file and start eclipse. You should see the new run configuration "Run Main". When you run it, EclipseFP executes your Main.hs file, redirecting both input and output to the console view.
Also, it seems that you haven't configured cabal yet. You first need to install it (from your distribution repositories, or here if you're using Windows). Then go to Scion and Cabal preferences and point them to your cabal executable. After you click OK the compilation of Scion should start. If it gives you errors, read what packages are missing and install them via cabal install pkg-name. (I had to install happy with --global flag, and for QuickCheck I had to manually set the 2.* version). To rerun Scion compilation, restart Eclipse.

Setting up Pylint with PyDev

I have installed pylint via easy_install. I can run pylint <filename> with success. But pydev refuses to use it.
I checked "use pylint"
I configured correct path
I updated my python interpreter in eclipse to have pylit in pythonpath
I use Eclipse Galileo
I have build automatically checked
I tried cleaning whole project and no errors
What am I doing wrong?
I'm guessing you may need to mark the folder that contains your code as a source folder. You can do this under project properties.
Project->Properties->PyDev-PYTHONPATH
add relevant folders to the list of sources.
I've noticed that Pydev won't run Pylint on files with dashes (hyphens) the the filename; according to the Pydev devs, '-' is not a valid Python module name character, and it doesn't look like they intend to fix it:
http://sourceforge.net/tracker/index.php?func=detail&aid=1915426&group_id=85796&atid=577329
http://sourceforge.net/tracker/index.php?func=detail&aid=2888890&group_id=85796&atid=577332
As if nobody writes scripts in Python... Grumble grumble...
To provide an alternative solution, pylint can be used as an External Tool in Eclipse. This requires having previously installed the pylint package for a Python installation.
Remember to first have a pylintrc file somewhere where pylint can find it, failing which a "No config file found" error is printed. Typically I would touch pylintrc inside the project directory, and keep the file in version control. For reference, see pylint command-line options.
In Eclipse, select Run, External Tools, External Tools Configurations.... Click the toolbar button to create a New launch configuration. Configure as below or as desired:
Name: pylint
Location: ${system_path:pylint}
Working Directory: ${project_loc}
Arguments: --reports=n "${resource_loc}"
Remember to click inside an open file to switch focus to it before running the above external tool for it. Failing this, an error can occur.
The output of the external tool will by default be printed to the console.
Related: Setting up pep8 as an External Tool in Eclipse