0

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. Errors

Community
  • 1
  • 1
noumenal
  • 1,077
  • 2
  • 16
  • 36

2 Answers2

1

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

enter image description here

RG_Glpj
  • 27
  • 4
  • The PYTHONPATH is clean. The sys.path is clean. The PEP 8 checker is enabled. See updated OP screenshot. – noumenal May 11 '16 at 09:35
  • Check if you have current directory (i.e. begin with '.') set in PYTHONPATH environment variable. And you can also use relative path as you said in your comment "from .. import Configuration". Or to be clean add '/path/to/src' to PYTHONPATH env. variable. – RG_Glpj May 11 '16 at 16:36
0

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

Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54