When i use eclipse to open an exist PyDev project, i find 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 of 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.
- Open eclipse which has installed PyDev plugin ( How To Run Python In Eclipse With PyDev ).
- Click Eclipse —> Preferences… menu item at eclipse left top menu in MacOS. If you use Windows OS, you should click Window —> Preferences menu item.
- Click PyDev —> Interpreters —> Python Interpreter menu item at left panel. If you can not see a python interpreter configured at right panel, then just add it. If there has one python interpreter added, maybe this interpreter is not correct, you should change it.
- Click Choose from list button at right panel, then select the python interpreter which you need in the popup dialog, generally we choose the newest python version.
- Click OK button, then select all the libraries that will be added in the PYTHONPATH system variable.
- Click OK button again, now you can see the python interpreter has been added. Select the python interpreter and click Libraries tab at right panel bottom, you can see the libraries list that you selected.
- 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.
To make the python interpreter change take effect, you need follow below steps, otherwise the Unresolved Import error still exist.
- Right click the PyDev project, then click Delete menu item in the popup menu list.
- Click OK button in the popup dialog to delete the project from eclipse. Please do not check Delete project contents on disk checkbox.
- Click eclipse menu item File —> Open Projects from File Systems….
- Click Directory… button and browse the exist PyDev project saved directory.
- Click Finish button to complete the PyDev project import. Now you can see the error has disappear.
- If you want to add third party python libraries into the eclipse PyDev project, you can read article How To Add Python Module Library In Eclipse PyDev