Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYTHONPATH hell with overlapping package structures

I'm having problems with my PythonPath on windows XP, and I'm wondering if I'm doing something wrong.

Say that I have a project (created with Pydev) that has an src directory. Under src I have a single package, named common, and in it a single class module, named service.py with a class name Service

Say now that I have another project (also created with Pydev) with an src directory and a common package. In the common package, I have a single script, client.py, that imports service.

So in other words, two separate disk locations, but same package.

I've noticed that even if I set my PYTHONPATH to include both src directories, the import fails unless the files are both in the same directory. I get the dreaded no module found.

Am I misunderstanding how python resolves module names? I'm used to Java and its classpath hell.

like image 656
Uri Avatar asked Oct 13 '25 04:10

Uri


1 Answers

I think in Python you are best off avoiding this problem by providing each package with a unique name. Don't name both packages common. Then you can import both with something like

import common1.service as cs
import common2.client as cc
like image 158
unutbu Avatar answered Oct 14 '25 17:10

unutbu