473,503 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import conflict

Hello,

I have a problem where I need to set up two separate Python projects
that each live under the same package. Once they are distributed,
they will live under the same filesystem path, but during development,
they are separated.

For example:
proj1/lib/pkg/foo/mod1.py
proj2/lib/pkg/bar/mod2.py

Furthermore, proj1 is dependent on proj2, so I want to be able to say
things like this, from within proj1:

import pkg.foo.mod1
import pkg.bar.mod2

Of course this doesn't work, even with a PYTHONPATH configured to see
both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
will be hidden from view.

Any suggestions?

Thanks!

May 7 '07 #1
3 1638
rp*******@sneakemail.com schrieb:
Hello,

I have a problem where I need to set up two separate Python projects
that each live under the same package. Once they are distributed,
they will live under the same filesystem path, but during development,
they are separated.

For example:
proj1/lib/pkg/foo/mod1.py
proj2/lib/pkg/bar/mod2.py

Furthermore, proj1 is dependent on proj2, so I want to be able to say
things like this, from within proj1:

import pkg.foo.mod1
import pkg.bar.mod2

Of course this doesn't work, even with a PYTHONPATH configured to see
both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
will be hidden from view.

Any suggestions?

Thanks!

Hi,
my only suggestion would be to overthink your project organization.
You can surely solve that problem with symlinks, but if they depend
on another, perhaps the structure is not optimal.
If you use python 2.5 you can try absolute imports (which I personally
find not so well):

from __future__ import absolute_import

See here: http://python.mirrors-r-us.net/dev/peps/pep-0328/

Cheers,
Stefan

May 7 '07 #2
rp*******@sneakemail.com schrieb:
Hello,

I have a problem where I need to set up two separate Python projects
that each live under the same package. Once they are distributed,
they will live under the same filesystem path, but during development,
they are separated.

For example:
proj1/lib/pkg/foo/mod1.py
proj2/lib/pkg/bar/mod2.py

Furthermore, proj1 is dependent on proj2, so I want to be able to say
things like this, from within proj1:

import pkg.foo.mod1
import pkg.bar.mod2

Of course this doesn't work, even with a PYTHONPATH configured to see
both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
will be hidden from view.

Any suggestions?

Thanks!

Hi,
my only suggestion would be to overthink your project organization.
You can surely solve that problem with symlinks, but if they depend
on another, perhaps the structure is not optimal.
If you use python 2.5 you can try absolute imports (which I personally
find not so well):

from __future__ import absolute_import

See here: http://python.mirrors-r-us.net/dev/peps/pep-0328/

Cheers,
Stefan
May 7 '07 #3
<rp*******@sneakemail.comwrote:
Hello,

I have a problem where I need to set up two separate Python projects
that each live under the same package. Once they are distributed,
they will live under the same filesystem path, but during development,
they are separated.

For example:
proj1/lib/pkg/foo/mod1.py
proj2/lib/pkg/bar/mod2.py

Furthermore, proj1 is dependent on proj2, so I want to be able to say
things like this, from within proj1:

import pkg.foo.mod1
import pkg.bar.mod2

Of course this doesn't work, even with a PYTHONPATH configured to see
both projects, because it will find 'pkg' in proj1/lib and so pkg.bar
will be hidden from view.
proj1/lib/pkg/__init__.py (and its counterpart under proj2) might set
their __path__ as to "merge" the two separate directories when seen as
Python packages. A rather contorted "solution" (compared to the simple
and obvious one of NOT "separating during development" parts that appear
to be so closely entwined) but I think it would work.
Alex
May 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2926
by: Paul Rubin | last post by:
That's what the Python style guides advise. They don't seem to like def frob(x): import re if re.search('sdfxyz', x): ... instead preferring that you pollute your module's global namespace...
3
6358
by: Rob B | last post by:
Hello, I am just starting to learn Python and was writing a simple script on my machine (Mac OS X 10.3.4), but I can't seem to import the random module: #!/usr/bin/env python import random
2
9989
by: Charles Fineman | last post by:
I've been asked to look over an integration toolkit that has a bunch of schemas to specify message format. There are a couple of strange things I noticed right off the bat and I wanted to get...
2
1802
by: Shapper | last post by:
Hello, In the main root of my web site together with my aspx and aspx.vb files I have the file global.vb. This file has a class with all the functions which are used in many aspx.vb files and...
11
1822
by: Connelly Barnes | last post by:
Hi, I wrote the 'autoimp' module , which allows you to import lazy modules: from autoimp import * (Import lazy wrapper objects around all modules; "lazy modules" will turn into normal...
2
2185
by: jobo | last post by:
I am importing bmp images into a jet database The embedded picture appears as a chunky square thumbnail with the filename in large font underneath. The size of the thumbnail and font seems to...
14
6868
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
10
1386
by: iu2 | last post by:
Hi all I've got three files: file a1.py: ======== the_number = None file a2.py: ========
5
5195
by: Stef Mientki | last post by:
hello, The import statement "import sqlite3" gives the error given below. In simple programs, the import statement (sometimes) succeed, and I can indeed access the database. So I guess there is...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.