How To Fix Unresolved Import Issues In Eclipse PyDev Project

When I use eclipse to open an existing PyDev project, I find an error message like Unresolved import: smtplib. This error means the python3 built-in library smtplib can not be found and imported in python source code now. This error is because the python interpreter is not configured correctly, now I will tell you how to fix it.

1. How To Change Python Interpreter Correctly In Eclipse PyDev Project.

  1. Open eclipse which has installed the PyDev plugin ( How To Run Python In Eclipse With PyDev ).
  2. Click Eclipse —> Preferences… menu item at eclipse left top menu in macOS. If you use Windows OS, you should click Window —> Preferences menu item.
  3. Click PyDev —> Interpreters —> Python Interpreter menu item on the left panel. If you can not see a python interpreter configured on the right panel, then just add it. If there has one python interpreter added, maybe this interpreter is not correct, you should change it.
  4. Click Choose from list ( for macOS) or New —> Choose from list ( for Windows ) button on the right panel, then select the python interpreter which you need in the popup dialog, generally we choose the newest python version.
  5. Click the OK button, then select all the libraries that will be added in the PYTHONPATH system variable.
  6. Click the OK button again, now you can see the python interpreter has been added. Select the python interpreter and click the Libraries tab at the right panel bottom,  you can see the libraries list that you selected.
  7. Now click Apply and Close button to close the python interpreter configuration panel to apply your changes.

2. How To Make Python Interpreter Change Take Effect.

  1. To make the python interpreter change take effect, you need to follow the below steps, otherwise, the Unresolved Import error still exists.
  2. Right-click the PyDev project, then click Delete menu item in the popup menu list.
  3. Click the OK button in the popup dialog to delete the project from eclipse. Please do not check Delete project contents on disk checkbox.
  4. Click eclipse menu item File —> Open Projects from File Systems…
  5. Click the Directory… button and browse the existing PyDev project saved directory.
  6. Click the Finish button to complete the PyDev project import. Now you can see the error has disappeared.
  7. If you want to add third party python libraries into the eclipse PyDev project, you can read the article How To Add Python Module Library In Eclipse PyDev

3. Question & Answer.

3.1 Unresolved import issue when import a python module from .py file.

  1. I have a python file /user/jerry/work/util/MySQLHelper.py, and this python file contains some utility functions which can operate the MySQL database. I want to invoke those functions in another python project, so I use the python sys module sys.path.append function to add the MySQLHelper module saved directory path to the new python project like below.
    import sys
    sys.path.append("/user/jerry/work/util")

    When I import the MySQLHelper module with the command import MySQLHelper in the eclipse Pydev project, it throws the error Unresolved Import Issues. My OS is Ubuntu, I think this error is not related to the OS. Can anyone tell me how to fix this error? Thanks a lot.

  2. If you use eclipse and Pydev, you can select your Pydev project in the eclipse left side Project Explorer panel, then click the Project —> Properties menu item on the top menu toolbar.
  3. Click the PyDev – PYTHONPATH item on the project properties window left side.
  4. Click the External Libraries tab on the window right side.
  5. Click the Add source folder button at the bottom of the External Libraries tab and select your python file saved folder ( in your case the folder should be /user/jerry/work/util).
  6. But first, you should add a __init__.py file in the source folder, then you can import the MySQLHelper module in your eclipse Pydev project.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.