Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydev shows unresolved import, but script runs?

I am using PyDev.

I am trying to organise my project classes into packages.

e.g. In a folder I have a module at /libraries/fund_price_library.py

In another file in my project, I try to import using:

from libraries.fund_price_library import FundPriceLibrary as fpl

PyDev underlines "FundPriceLibrary as fpl" in red, marking it with this error:

unresolved import fpl

However, my script works perfectly fine, so I believe that I am doing the import correctly.

I have lots of similar errors all over my project, and it looks messy. However, my python code works, so I assume I am importing correctly.

How do I suppress these errors?

like image 368
Ginger Avatar asked Oct 05 '13 16:10

Ginger


People also ask

How to fix an unresolved import?

To solve unresolved import error in Python, set your Python path in your workspace settings. If you are working with Visual Studio Code and import any library, you will face this error: “unresolved import”. Then reload the VSCode, and it will fix that error.

What does unresolved import mean?

An import and export each consist of a procedure or data type and a name. An unresolved import is one whose type and name do not yet match the type and name of an export. A resolved import is one whose type and name exactly match the type and name of an export.

How do I start programming in PyDev?

Go to File → New → PyDev Project to start a wizard. In the next window that appears, enter the name of your project and select "python" and 3.0"; as the type. Make sure "create default 'src' folder and add it to the pythonpath?" is selected. Click Finish.

What is a PyDev module?

PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython development. It comes with many goodies such as: Django integration. Code completion. Code completion with auto import.


2 Answers

This question might hold the solution to your problem.

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.

It might just be that PyDev doesn't know where to find the files.

like image 104
Wayne Werner Avatar answered Oct 10 '22 04:10

Wayne Werner


I had the same issue. Solution is (I have Eclipse 4.6 w/ Pydev 5.6):

Project > Properties > PyDev - PYTHONPATH > tab Source Folders

Do this: Add source folder (button) and add your (current) source dir, in my case it was src subdir so new item apears in the window : /${PROJECT_DIR_NAME}/src

So now I have this there:

/${PROJECT_DIR_NAME}
/${PROJECT_DIR_NAME}/src

and my PyDev is happy now :)

like image 35
martin-voj Avatar answered Oct 10 '22 02:10

martin-voj