Unresolved import error with pydev while using from-import-as - eclipse

In Eclipse with PyDev I get an Unresolved import: pilImage error while having this code.
The code works well when executed from inside PyDev or shell, but the IDE is high-lighting me this as an error.
from PIL import Image as pilImage
# do something with pilImage
How can I solve the problem?

I think it may be a bit of a misunderstanding on how PIL should be used...
PIL has a rather uncommon packaging, in which the PIL library is added to the PYTHONPATH (and not the directory containing it), so, if you install with easy-install, it'll do something as:
/Lib
/Lib/site-packages
/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg
/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg/Image.py
So, the import that should actually be done is: import Image as pilImage (i.e.: no from PIL in the import).
A reference backing up that this is how the import should be: http://effbot.org/imagingbook/introduction.htm
And in this case, the directory added to the PYTHONPATH should be: "/Lib/site-packages/PIL-1.1.7-py2.6-win32.egg"
Note that your import could work if you renamed the directory /Lib/site-packages/PIL-1.1.7-py2.6-win32.egg to /Lib/site-packages/PIL and just left /Lib/site-packages/ in the PYTHONPATH (in which case you still would need to go to the PyDev interpreter configuration and just press apply so that it finds out that a new PIL package was added to the PYTHONPATH -- note that in this case /Lib/site-packages/PIL should NOT be added to the PYTHONPATH)

Did you install PIL as an egg after installing PyDev? If so, PyDev won't know it's there. Remove and re-add the interpreter to fix this. See this SO question for more.

Are you sure that your PyDev-configured interpreter knows the PIL-package and it's contents?
If you configured your PyDev Python-interpreter before you installed the PIL-packages, it doesn't know anything about it.

Sometimes PyDev requires you to restart Eclipse in order to correct the wrong error message. It's often caused when a user writes the import before adding the module.

Related

PyDev doesn't auto-complete my imported modules

I have Eclipse 4.7.3 with PyDev installed. When I import modules from another directory (or any for that matter) pydev doesn't show a warning that it can't find the import but it doesn't do autocomplete for functions within that import.
Ex import DataDefines as df and then when using it like df.INSERTFUNCTIONHERE it doesn't give any usefull suggestions for functions found in that file. When I run it, it grabs the imports fine but I want to be able to auto-complete for syntax and spelling reasons. What could be going wrong? I have configured my python interpreter which helped make the program actually run and I have modified settings in Preferences -> PyDev -> Code Completion but now I am stuck.
Are your sources under a source folder?
Have you tried following the getting started?
http://www.pydev.org/manual_101_root.html
If you're not able to figure out from that, please provide a screenshot of your pydev package explorer showing the modules you have and the actual issue on the completion.

Eclipse Blender and PyDev Unresolved import pydevd

I have python installed at:
C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32
My PATH variable is:
C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32\Scripts\;
C:\Users\xxxx\AppData\Local\Programs\Python\Python35-32
And I have this in Eclipse:
And finally I have this -.- (you can see that 'import sys' works:
Ok, I find what was wrong.
First, it is needed to download module, in this case pydevd
Be careful, download not latest (like I did wrong first time) but with version of python it is installed.
In my case it is Python 3.5.3 so I choose:
pydevd-1.3.0-cp35-cp35m-win32.whl
Then install it with pip, it is easy:
pip install C:%where_it_is_downloaded%/pydevd-1.3.0-cp35-cp35m-win32.whl
Then there will be pydevd added to Packages beside pip and setuptools:
And one more thing.
Compare this 2 screens. Path to site-packages has to be changed from lib to Lib.
As a tip, as the debugger is usually only temporarily used, so, you could just use the internal version from PyDev if you're Ok with the unresolved imports and just want to connect the remote debugger to Blender.
You could do that by using the pydevd template (i.e.: write inside PyDev pydevd and press Ctrl+Space and the option which would add it to the PYTHONPATH and then connect to the remote debugger would appear).
See: http://www.pydev.org/manual_adv_remote_debugger.html for more details on the remote debugger.

Different Import Statement Required in Eclipse

I am using the same Python (2.7) Git branch on two different computers. On one of the computers I am running Eclipse and everything builds smoothly without any errors. In Eclipse I have also configured an external library.
When I try to run the same code from command line using Python I have to change the following import statement
from src.configuration import Color
to
from configuration import Color
for the import to work on the second computer. This applies to all local import statements. Now, when I push the changes onto Git and pull on the other computer, I receive Unresolved Import errors in Eclipse.
I have been able to isolate the error to Eclipse, as I am able to run the main module without the src.* in Python also from command line. (The grammar in Eclipse is also set to 2.7)
How can I resolve this?
EDIT: This is possibly related to How to fix "Attempted relative import in non-package" even with __init__.py
Below is the folder/package structure and the errors.
Make sure the Python version in Eclipse is the same as on your second computer. And the python interpreter includes all the libraries, to check this on Eclipse use menu option windows->preferences->Interpreter-Python as in image below (the python version you may have could be different but it should not matter when comparing with your's) In the top section it shows the Python version Eclipse is using, you can change it if it is not correct. And in bottom section it shows the list of Python libraries. My guess is you have src folder under Python\Lib\site-packages, if that is the case you will need to
There are differences between the Python Path and Python Src path for the eclipse or project instance being used
Its the only reason we see a difference of code change due to dependencies of Python Path or Src path set with eclipse

Pydev say, "Unresolved import" error

hm..
Sometime, PyDev say "Unresolved import error".
In my environment
Python2.6.6 Eclipse3.7 PyDev2.2.2
Errors are.
> Unresolved import: pycassa -> import pycassa Unresolved import:
> WebSocketHandler -> from geventwebsocket.handler import
> WebSocketHandler Unresolved import: tweepy -> import tweepy
Is there any helpfull information?
Had the same problem. In the end I was able to fix the problem by deleting my old interpreter in Preferences > PyDev > Interpreters, and creating a new interpreter called "python" which had the correct paths. After quitting and reopening eclipse, pydev found all my modules.
Probably your PYTHONPATH is not set properly (or if those are libraries in the interpreter, maybe you added them after configuring it).
See: http://pydev.org/manual_101_interpreter.html for references (note the part on forced builtins there as it might be your case).
You get an unresolved import if the required module cannot be found. Modules are searched for in the current working directory and the directories listed in sys.path. Your python cannot find the modules pycassa and tweepy it appears.
Might want to check this: http://klaith.wordpress.com/2009/06/12/pydev-unresolved-import-errors/
I solved by recreate the interpreter. There is a guide at pedev.org:
What if I add something new in my System PYTHONPATH after configuring
it?
If you add something to your python installation, you need to either
add it manually as a 'new folder' in the System PYTHONPATH (if it's
still not under a folder in the PYTHONPATH) or (recommended) remove
your interpreter and add it again, then, press apply.
Note that if you added a library that's already under a folder in the
PYTHONPATH, you have to at least go to the interpreter preferences and
press apply so that it clears its internal caches (after the
configuration is done, things are set in stone for PyDev)
Thanks for Fabio Zadrozny and nicodjimenez.
I had a similar problem before. I solved the problem by this steps:
1)Window > Preferences > PyDev > Interpreters > Python Interpreter
2)Delete the Python Interpreter path you added previously
3)Add "New" Python Interpreter and choose python.exe path
4)Check Libraries tab (I found the problem at this step.)
Check your path name, is it true or false? Eclipse detect "C:\Python27\lib" but it should be "C:\Python27\libs" and "C:\Python27\Lib".
In the properties for your pydev project, there's a pane called "PyDev - PYTHONPATH", with a sub-pane called "External Libraries". You can add source folders (any folder that has an init.py) to the path using that pane. Your project code will then be able to import modules from those source folders.
Check this two links it may be helps to you,
Unresolved Import Issues with PyDev and Eclipse
Unresolved import: models
Is pycassa found as a symlink within a directory on your PYTHONPATH? Pydev apparently has a bug where its code analysis cannot follow symlinks (and hence will not see your libraries). The python interpreter can though of course.
I was having a similar problem with the dbfpy module.
I had downloaded the tar archive and installed the source files in /usr/lib/python2.7/dist-packages
With this I was able to import the packages in IDLE and even run the code in Eclipse. However the pydev import was still showing as an error with the message "unresolved import"
As suggested by Fabio, I checked the PyDev documentation for forced-builtins. Just adding the name of the package ("dbfpy" in my case to the Forced Builtit tab of Python Interpretr in Eclipse) solved the issue.
(I know the answer is a bit late)
if you installed a python package using, for example: pip install django
i solved the unresolved import issue doing this:
In eclipse:
Window > Preferences
In the left panel tree structure go to:
PyDev > Interpreter - Python
In the upper right panel be sure to have the correct interpreted selected
and in the bottom right panel, click New Folder, navigate to your python installation site-packages (usually in c:\Python33\Lib\site-packages) and search for a folder that ends with .egg-info
In my pc it is "C:\Apps\Environments\Python33\Lib\site-packages\Django-1.5.4-py3.3.egg-info" since i installed python in C:\Apps\Environments, should be different in your case.
This worked with django and selenium, should work with all others as well (as far as i know)
Adding the corresponding package folder ending with '.egg-info' to PyDev > Interpreter - Python - library will resolve the problem.
In Linux, it is usually under /usr/local/lib/pythonX.X/dist-packages
Add site-packages path in environmental variables.
Right click on
computer -> properties -> advanced system settings -> Environmental
variables
.
After that is done, remove the python interpreter and add it again in eclipse.
right click project name in
eclipse --> properties --> python interpreter
.
Hope it works.

Can't find matplotlib with Eclipse?

I'm having some issues with matplotlib in Eclipse (on Mac),
So I've installed matplotlib because it's necessary for a project I'm working on. It works if I run it through Terminal -- but when i try to run the program or do anything with matplotlib within Eclipse, I get an error message saying that there is no module named matplotlib. I added the matplotlib folder that is within my standard site-packages folder to the system PYTHONPATH within Eclipse, but still doesn't work.
Any suggestions would be greatly appreciated!
I just had the same issue and could resolve it by removing any additional paths I manually added to the PYTHONPATH of the specific project.
Hope that helps
Cherio Woltan