Reputation: 471
I'm probably doing something really dumb here, but it's driving me crazy.
I have two PyDev projects in Eclipse. One project, 'Analysis' depends on the other, 'PyCommon'. I'm 100% sure of this as when I look at the project references for Analysis, PyCommon is checked, and automatic import/code completion works when I reference elements in PyCommon from Analysis.
I'm trying to write/run a module in Analysis. The module is fhb/analysis/log_parsers.py.
I'm trying to import the element OrderStatus from fhb/pycommon/types/order_status in the PyCommon project. So, my import statement is
'from fhb.pycommon.types.order_status import OrderStatus'
PyDev clearly knows where this is because that import statement was written automatically by PyDev on a quickfix correction. Nonetheless, when I try to run the main function in log_parsers.py, I get this:
Traceback (most recent call last): File "/workspace/Analysis/src/fhb/analysis/log_parsers.py", line 6, in from fhb.pycommon.types.order_type import OrderType ImportError: No module named pycommon.types.order_status
All of these packages are under a proper source folder ('src') in each project.
Also, even though Analysis absolutely is set to reference PyCommon , when I look under PyDev-PYTHONPATH in Analysis's properties, only Analysis's own src folder appears under the 'Source Folder' tab, and it's the only project I see if I click on 'Add source folder'
Upvotes: 9
Views: 5225
Reputation:
Your problem may come from __init__.py being missing from some of your module folders.
For your example, for using OrderStatus from order_status.py in fhb.pycommon.types.order_status, you need to have a (possibly empty) __init__.py file in fhb, fhb/pycommon, and fhb/pycommon/types.
Also note that for pylint to work correctly for fhb/analysis/log_parsers.py, you need to have an __init__.py in fhb/analysis as well.
Upvotes: 0
Reputation: 383
I think pydev is having trouble with similar package names near the root of the package name "fhb". I'm having the same problem. Removing the packages in one of the projects let me reference the other one without a problem.
I couldn't solve the problem, but I think it has to do with the root folder of the package being the same.
Upvotes: 2
Reputation: 25332
The best way to check where the problem lies is by putting:
import sys
print('\n'.join(sorted(sys.path)))
in the entry of your program to see if the PYTHONPATH is properly set as you expect...
See: Importing from another project in pydev for details on how the structure is supposed to look like (in the worst case, if it's already configured, it could be a PyDev cache bug -- restarting Eclipse would fix it in this case -- otherwise, it's probably some misconfiguration).
Upvotes: 3
Reputation: 21
I believe you have to add the path of PyCommon into PYTHONPATH or else it won't be able to find the actual modules to import.
Upvotes: 0