473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with pythonpath

Hi, im a newbie both to python and this list.
I hope someone can help me whith this:
I have a directory structure like this:

..
|-- src
| `-- pkg
| |-- __init__.py
| |-- main.py
| `-- spkg1
| |-- __init__.py
| `-- config.py
`-- src2
`-- pkg
|-- __init__.py
`-- spkg2
|-- __init__.py
`-- config2.py

and main.py is a python script that contains this imports:

from pkg.spkg1 import config
from pkg.spkg2 import config2

executed in linux whith this:

env PYTHONPATH=src:src2 src/pkg/main.py
Traceback (most recent call last):
File "src/pkg/main.py", line 4, in ?
from pkg.spkg2 import config2
ImportError: No module named spkg2

changing the order of the python path only inverts the problem, is there
any way to solve this without changing the directory structure?, or am i
doing something wrong?.
Thanks for your help and excuse my bad english.

Jul 19 '05 #1
1 1306
mg
Tim Roberts wrote:
Observer <ob******@moscomono.ath.cx> wrote:

Hi, im a newbie both to python and this list.
I hope someone can help me whith this:

I have a directory structure like this:
.
|-- src
| `-- pkg
| |-- __init__.py
| |-- main.py
| `-- spkg1
| |-- __init__.py
| `-- config.py
`-- src2
`-- pkg
|-- __init__.py
`-- spkg2
|-- __init__.py
`-- config2.py

and main.py is a python script that contains this imports:

from pkg.spkg1 import config
from pkg.spkg2 import config2


executed in linux whith this:

env PYTHONPATH=src:src2 src/pkg/main.py
Traceback (most recent call last):
File "src/pkg/main.py", line 4, in ?
from pkg.spkg2 import config2
ImportError: No module named spkg2

changing the order of the python path only inverts the problem, is there
any way to solve this without changing the directory structure?


Nope. When Python goes to look for a package called "pkg", it starts at
the beginning of PYTHONPATH and stops as soon as it finds one. You either
need to use different names for the two packages (pkg1, pkg2), or use a
symbolic link to link spkg2 into the src directory.

If I remember, I think you need to add an __init__.py file just in your
directories src & src2.
Moreover, you can add the path of src and src2 to the variable sys.path
at the beginning of your main script (in that case, it not necessary to
define PYTHONPATH)

I hope I help you
Mathieu
Jul 19 '05 #2

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

Similar topics

2
by: Tim | last post by:
Maybe I've been working too long, but has anyon had their python interpreter stop taking commands. The IDLE version works fine, but under Windoze: 1) execute "python" in teh command shell 2)...
4
by: r.e.s. | last post by:
I have no PYTHONPATH nor any other python-related environment variables, yet everything seems fine. (I'm using PythonWin with winxp.) As long as modules are loaded through PythonWin, is...
8
by: Tero Pihlajakoski | last post by:
Hi, I've been experimenting on embedding Python to a C software, and ran into a little problem with PYTHONPATH (I'm running on linux). Here's the deal: When trying to call...
3
by: D Denholm | last post by:
I recently installed Python 2.2 on my WinXP box. I am having problems figuring out how to create the PYTHONPATH correctly. I went to the WinXP SystemProperties > Advanced > Environment...
1
by: D.S. Hein | last post by:
I have installed python 2.3 on my Windows 2K laptop and I can run python from the command prompt. I have tried various ways to set PYTHONPATH with the various directories where I have python...
10
by: sushant.sirsikar | last post by:
Hi, I am using Linux env.I set the PYTHONPATH using import sys sys.path.append(----) But we i close python and start again i is not showing my new entry in PYTHONPATH. Can anyone help me to...
0
by: Michael Yanowitz | last post by:
Hello: Someone on my team tried out installing my Python code and found that setting PYTHONPATH does not work, but setting PATH environment variable works the way PYTHONPATH should. Is that how...
3
by: rh0dium | last post by:
Hi all, Can anyone help me out. I would like to have python automatically look in a path for modules similar to editing the PYTHONPATH but do it at compile time so every user doesn't have to do...
1
by: Aljosa Mohorovic | last post by:
i have a working MySQLdb module (/usr/lib/python2.4/site-packages/ MySQL_python-1.2.2-py2.4-linux-i686.egg), using it without problems. "clean shell" after login: python -c "import MySQLdb"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...
0
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...

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.