PyDev import in eclipse - eclipse

I just installed Eclipse Indigo, in Ubuntu 10.04 LTS, and installed Pydev with it. I did the following:
(1) set python interpreters by pressing Auto config in Window > Preferences > PyDev > Editor > Interpreter-Python
(2) set system Pythonpath through Window > Preferences > PyDev > Editor > Interpreter-Python
(a) pressed New Folder and added /usr/lib/python2.6
I am trying to run an openrave code in eclipse and have all the required openrave libraries installed. "openravepy" is in the directory /usr/lib/python2.6/dist-packages.
My problems is that it seems that the import is not successful that a few function calls return error type : PyDev Problem. It says 'Undefined Variable: ...'
here are some snippets of the code:
from itertools import izip
from openravepy import *
from numpy import *
import time
class FastGrasping:
class GraspingException(Exception):
def __init__(self,args):
self.args=args
def __init__(self,robot,target):
self.robot = robot
self.ikmodel = databases.inversekinematics.InverseKinematicsModel(robot=robot,iktype=IkParameterization.Type.Transform6D)
--databases is part of openravepy and described as undefined variable.
I've read a few threads and I already did the following
(1) Remove and readd pydev
(2) I've run the code previously, it used to work with eclipse helios and pydev setup. so, I Deleted and reinstall eclipses helios and indigo and repeat the process of adding pydev and pythonpath again and again.
Anyone know hows can I fix this? or is this a bug in pydev?
thanks in advance.
cheers

Have you tried adding 'openravepy' to the forced builtins (see: http://pydev.org/manual_101_interpreter.html for details)?
Also, does it run properly? (i.e.: the issue only happens in the PyDev code-analysis or also when you run the code in Python from within PyDev?)

I have found that the Auto config does not always auto select the site-packages directory. This is where most installed modules reside, numpy for example on my machine. Try doing auto-config once more and also select the directory ending in site-packages, if you have not done so already.

Related

’unresolved import’ message for streamlit in Eclipse PyDev

I have successfully installed the streamlit package using the following
shell command and can run the resulting local server localhost:8501
Python3.8 -m pip install streamlit
In Eclipse, the module appears under the Package Library in the Python Interpreter.
I can import it as a library item in a PyDev module as as follows:
import streamlit
The only note I get from the compiler is that streamlit is an ‘unused import’. However, when I append the command as follows the compiler then says ‘unresloved import st’
import streamlit as st
Both ‘import streamlit’. and ‘import streamlit as st’ will not code complete.
How can I clear the ’unresolved import’ message ?
The sys.path is as follows:
/Users/davidklemitz/eclipse-workspace/streamlit
/Users/davidklemitz/eclipse-workspace/streamlit
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
Thanks in advance for any help.
I solved the problem. Turns out it was a compound of two issues.
First the name of the PyDev module I chose was the same name as the package module name streamlit.py, installed using the following command
Python3.8 -m pip install streamlit
Second, I had a look at the PYTHONPATH under Eclipse->Preferences-> PyDev->Interpreters-> Python Interpreter where these paths were arranged as follows:
/Library/Frameworks/Python.framework/Versions/3.8/lib
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
As streamit.py was in the second and not the first, I reversed the order, restarted Eclipse, created a new PyDev project and associated development model named stream_lit.py and the code completed as expected.

PyDev unresolved import errors on intra-package modules when using Grammar 3.x

I think there is a bug with respect to how PyDev (version 4.6) recognizes intra-package imports when selecting Grammar 3.x for the project preferences. I have a project like this:
foobar
mypack
__init__.py
mod1.py
mod2.py
mod2.py simply says
from mod1 import fun1
mod1.py simply says
def fun1():
print("Hey we are in fun1 in mod1")
If the project Python project preferences are set to use Grammar 3.0-3.5, with a Python 3.4 interpreter, and I open up mod2.py the line from mod1 import fun1 is highlighted with an error Unresolved import: fun1. If I change the Python project preferences to use Grammar 2.7, close the file mod2.py and reopen it, the error disappears. Just by changing the grammar back and forth, and closing/reopening the file, I can make the error appear/disappear.
So it seems that setting the Grammar to 3.x in PyDev causes intra-package imports to be incorrectly flagged as having an import error.
Any suggestions?
PyDev is doing right... on Python 3, relative imports must be written as:
from .mod1 import fun1
If the import doesn't start with a dot, it'll consider it an absolute import (and will properly show the error for you as with that absolute path the imported file cannot be resolved).
So my real issue was getting PyDev to not report errors about the imports, and to be able to debug modules buried in packages that have a main() in there for debugging. The solution for me was to use relative imports (as said in Fabio's answer), and then to do the following for debugging purposes. Let's say I want to run a module pack1.subpack2.subpack3.subpack4.modtodebug using PyDev, that has relative imports, and has a main() function. At the top level of my project, I have a module debugmain.py that reads
from pack1.subpack2.subpack3.subpack4.modtodebug import main as debugmain
if __name__ == '__main__':
debugmain()
I then have one run configuration for debugmain.py and each time I want to debug a different module, I just have to edit the code in debugmain.py to point to that module.
I hope this helps someone else with this kind of problem.

Import issues - is my Jython installed correctly?

I'm starting using Jython. I noted that sys.path is completely different when Jython is executed from the command line than from Eclipse.
Command line
tk:~$ jython
Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36)
[Java HotSpot(TM) Server VM (Oracle Corporation)] on java1.7.0_10
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['',
'/jproject/extras/2.5.3/Lib',
'__classpath__',
'__pyclasspath__/',
'/jproject/extras/2.5.3/Lib/site-packages']
It's OK, I can import everything from there (import pdb, import csv, etc).
Eclipse
I added jython.jar in Eclipse to the Java Build Path using the "Add JARs" button. I wrote a simple Java class (excerpt):
PythonInterpreter pi = new PythonInterpreter();
pi.exec("import sys");
pi.exec("print sys.path");
Output:
['/jproject/projects/foobar/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/MyProject/WEB-INF/lib/Lib',
'__classpath__',
'__pyclasspath__/']
From Python scripts created in the Java project I can't import anything. I always get ImportError: No module named ...
So I created a file called .jython in my home directory containing this:
python.path=/jproject/extras/2.5.3/Lib:/jproject/extras/2.5.3/Lib/site-packages
It seems to fix the import issue. But, is this the right way to proceed?
I think I don't have to do the last step manually and probably I installed Jython badly.
Looks like I have same issue described in my question here:
The solution I've come up is workaround that doesn't require any actions from user to set python.path: Basically I added code that sets python.path to application work directory (user.path) before initializing jython environment.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script7.groovy: 1: unable to resolve class

I am currently receiving this error when trying to run a soapui file:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed: Script7.groovy: 1: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate # line 1, column 1.
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148)
at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1206)
at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148)
at org.codehaus.groovy.control.CompilationUnit$6.call(CompilationUnit.java:585)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:472)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:292)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:727)
at groovy.lang.GroovyShell.parse(GroovyShell.java:739)
at groovy.lang.GroovyShell.parse(GroovyShell.java:766)
at groovy.lang.GroovyShell.parse(GroovyShell.java:757)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:141)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
1 error
soapUI code:
import com.company.ui.test.SoapUI_T11001_StockConsSecurityCurBusiDate
def env = testRunner.testCase.testSuite.project.getPropertyValue("env")
def baseUrl = testRunner.testCase.testSuite.project.getPropertyValue("baseUrl")
log.info("The baseurl is "+baseUrl)
log.info("The env under test is "+env)
SoapUI_T11001_StockConsSecurityCurBusiDate testStep = new SoapUI_T11001_StockConsSecurityCurBusiDate();
testStep.init(baseUrl);
testStep.execute(null);
eclipse code:
package com.company.ui.test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.eviware.soapui.model.support.AbstractSubmitContext;
import com.eviware.soapui.model.testsuite.TestRunner;
public class SoapUI_T11001_StockConsSecurityCurBusiDate extends BaseSelenium{
public static void main(final String[] args){
final SoapUI_T11001_StockConsSecurityCurBusiDate ico = new SoapUI_T11001_StockConsSecurityCurBusiDate();
try{
ico.init("https://avncedevn1.nam.nsroot.net:17620/", false);
}catch(Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
}
ico.execute(null);
}
//...code....
}
how do I solve this error ? I'm not sure what is causing the error.
This work for me:
Press Ctr+Alt+Shift+s
or:
From File menu -> Project Structure -> SDK Location -> JDK location Drop down menu choose:
Embeded JDK c:....\jre
Then ok.
If you using android studio and got this error then I solved it changing the Gradle version of the project to the newest version 6.2.1 on the project structure options.
One of the possible reasons is that the jdk version is too high. For example, using jdk 16 to build the source code of Apache Kafka throws this error. Using jdk 11 is fine.
bild.gradel file in change clashpath
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
}
gradel-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
I'm Using Android Studio - Arctic Fox and this worked for me
Go To File menu -> Project Structure -> SDK Location -> Gradle Setting
Then check the "Download external annotations for dependencies" button and select JDK location from the drop down menu and choose: Android Default Jdk Vesion.
Click on Ok.
If you wanted to make a new project on Android Studio after first install, probably you write your application name including (') sign as called apostrophe.
For Example, I tried to set a name as: "Henry's Game" but apostrophe caused Android Studio to not load because of this mistake:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
So, just change your application's name, and simply use Latin alphabet languages such as English.
To fix: Go to your Android Project Tree and find Gradle Scripts > settings.gradle > change the name:
rootProject.name='Henry Game'
include ':app'
With Eclipse Juno (Kepler Release) Build id: 20121114-2344, I found similar problem:
org.codehaus.groovy.control.multiplecompilationerrorsexception startup failed unable to resolve class Chart
The class Chart is my container class for some utilities for charting.
I tried outside of Eclipse, with Groovy 2.0 Console the same code segment works fine. After scratching my head for about 3 hours, I resolved it by adding the following
import excel.Chart
in the invoking class with main() that has "new Chart()" thus getting the complaints, once added, the error is gone. Even more weird, after passing the error, I remove that import, there is still no more complaints! (All my scripts/classes are under the same package excel, I suppose such import statement is not needed.)
One of the symptom of the complaints is that there was not Chart.class generated in the output bin folder. Once the complaints gone, Chart.class appeared there.
I guess that it might be a bug of Eclipse/Groovy plugin (I use Groovy Plugin for Juno).
Hope my understanding is correct, and it helps.
The solution for me was change the gradle version and the Gradle JDK:
File > Project Structure > Project
enter image description here
File > Project Structure > SDK Location
enter image description here
Go to Files and click Invalidate caches/ Restart . Android studio will clear the cached and it will be restarted without any error.
Hope this answer helps you :)
For this problem, you might also encounter package naming from gsp as I did. In the build/gsptmp folder, Grails 4.x.x creates temporary gsp files to link the classes that they refer to. Due to the change of a package name it was failing to do so in my case. Try with command grails war --stacktrace during war build!
Previously, it was <%# page import="bv.BankReconciliationController" %>
but the folder bv was renamed to factoring.
So, the solve was to change the import to
<%# page import="factoring.BankReconciliationController" %> and it worked :)
I have also faced the same and tried all of the solution here and other places as well, at last i deleted my .gradle and gradle both folder and caches of android studio and open the studio again and rebuild the project, it's works after that fine and used the latest gradle version and previously it was picking up the older version and causing issues.
for me , solution is to upgrade the gradle to latest version , and remove the .idea file , and invalidate caches and restart android studio.
When starting a project make sure to select SDK version 11 or later. It will default to a minimum SDK but you have to scroll down to a later version for it to work. Then the project should load and build.
For me, I just delete the .grade file under program files(C:\Users\username\ .gradle) in windows and it will work.
This work for me:
From File menu -> Project Structure -> SDK Location -> klik Gradle Setting for show hide menu, Gradle JDK choose:
Embeded JDK c:....\jre
Then ok.
Do you have the grail and groovy plugin installed? If so try uninstalling this plugin. I had the same error message and uninstalling the plugin, restart IDE worked for me.

"import as" leads to unresolved import error, "from .. import" does not

I'm trying to write some plugins for the irc bot supybot with eclipse/pydev. Pydev gives me errors about unresolved imports on supybot-modules/packages (e. g. import supybot.utils as utils), but works ok on e. g. "from supybot.commands import *". So I guess I set up dydev correctly, as it finds the wanted modules. The problem must be in pydev/eclipse, as the bot works correct and in eric5 I get also no errors about that.
Removing the interpreter and setting it up didn't help. Any other ideas on how to fix this? System: Arch Linux, Eclipse Juno, PyDev 2.7.1, wanted (and set up) python interpreter is 2.7, supybot is installed in site-packages for Python 2.7.
Edit: Just noticed: PyDev doesn't mark the "from ... import *" as error, but if I use functions imported from there I get an error on that function.
Code sample:
[...]
import supybot.utils as utils
from supybot.commands import *
[...]
wunsch = wrap(wunsch, ['text', 'now'])
[...]
Error on the first line: Unresolved import: utils
Second line gets no error nor warning
Error on 3rd line: Undefined variable: wrap
But 'wrap' is a function declared in supybot.commands
Run import supybot; print supybot.__path__ to get the path to the supybot package. PyDev may be importing the wrong one (for example if you use a folder called supybot in your workspace).