Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61523 > unrolled thread
| Started by | smilesonisamal@gmail.com |
|---|---|
| First post | 2013-12-10 19:56 -0800 |
| Last post | 2013-12-10 22:02 -0700 |
| Articles | 8 — 5 participants |
Back to article view | Back to comp.lang.python
python import error smilesonisamal@gmail.com - 2013-12-10 19:56 -0800
Re: python import error Michael Torrie <torriem@gmail.com> - 2013-12-10 21:25 -0700
Re: python import error John Gordon <gordon@panix.com> - 2013-12-11 04:53 +0000
Re: python import error smilesonisamal@gmail.com - 2013-12-10 21:45 -0800
Re: python import error Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-12-10 23:23 -0800
Re: python import error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 09:51 +0000
Re: python import error John Gordon <gordon@panix.com> - 2013-12-11 16:15 +0000
Re: python import error Michael Torrie <torriem@gmail.com> - 2013-12-10 22:02 -0700
| From | smilesonisamal@gmail.com |
|---|---|
| Date | 2013-12-10 19:56 -0800 |
| Subject | python import error |
| Message-ID | <93405ea9-6faf-4a09-9fd9-ed264e3136e1@googlegroups.com> |
Hi,
I am a new bie in python I was trying to execute the python script aaa.py in fedora which imports different modules. Actually when I am executing the aaa.py I am getting the following error and PYTHON_PATH=/bin/python which has a symlink to python-2.7. Please help me in this regard? I am not getting any clue where I am wrong.
python -c "import sys; print sys.path"
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gst-0.10', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
aaa.py
=======
Traceback (most recent call last):
File "aaa.py", line 5, in <module>
from ccc.ddd import sss
ImportError: No module named ccc.ddd
directory structure as follows:
ccc
|
ddd
|
aaa.py
sss.py
Regards
Pradeep
[toc] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-12-10 21:25 -0700 |
| Message-ID | <mailman.3867.1386735979.18130.python-list@python.org> |
| In reply to | #61523 |
On 12/10/2013 08:56 PM, smilesonisamal@gmail.com wrote: > Traceback (most recent call last): > File "aaa.py", line 5, in <module> > from ccc.ddd import sss > ImportError: No module named ccc.ddd > > directory structure as follows: > > ccc > | > ddd > | > aaa.py > sss.py This is because directories have no inherent meaning to python. A module is normally a file. If you want to group a bunch of files together you have to use a package. See the docs on how to make a package. But the namespace structure within a package isn't based on the directory tree either. It's usually set up by __init__.py within the package which imports modules defined in the package into the namespace. http://docs.python.org/3/tutorial/modules.html#packages Hope this helps.
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-12-11 04:53 +0000 |
| Message-ID | <l88r4e$mhe$1@reader1.panix.com> |
| In reply to | #61523 |
In <93405ea9-6faf-4a09-9fd9-ed264e3136e1@googlegroups.com> smilesonisamal@gmail.com writes: > File "aaa.py", line 5, in <module> > from ccc.ddd import sss > ImportError: No module named ccc.ddd > directory structure as follows: > ccc > | > ddd > | > aaa.py > sss.py A python file isn't importable unless the directory also contains a file named __init__.py . Try making __init__.py files in the ccc and ddd directories. If you don't know what to put in them, just leave them blank. -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | smilesonisamal@gmail.com |
|---|---|
| Date | 2013-12-10 21:45 -0800 |
| Message-ID | <58f7bd2a-ef82-4782-b4fb-db824f9c8e44@googlegroups.com> |
| In reply to | #61526 |
On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote: > In <93405ea9-6faf-4a09-9fd9-ed264e3136e1@googlegroups.com> smilesonisamal@gmail.com writes: > > > > > File "aaa.py", line 5, in <module> > > > from ccc.ddd import sss > > > ImportError: No module named ccc.ddd > > > > > directory structure as follows: > > > > > ccc > > > | > > > ddd > > > | > > > aaa.py > > > sss.py > > > > A python file isn't importable unless the directory also contains a file > > named __init__.py . > > > > Try making __init__.py files in the ccc and ddd directories. If you > > don't know what to put in them, just leave them blank. > > > It is having __init__.py as blank in ccc and ddd directories. But it still doesnot work. > -- > > John Gordon Imagine what it must be like for a real medical doctor to > > gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
|---|---|
| Date | 2013-12-10 23:23 -0800 |
| Message-ID | <mailman.3870.1386747033.18130.python-list@python.org> |
| In reply to | #61528 |
On Tue, Dec 10, 2013 at 9:45 PM, <smilesonisamal@gmail.com> wrote: > On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote: >> In <93405ea9-6faf-4a09-9fd9-ed264e3136e1@googlegroups.com> smilesonisamal@gmail.com writes: >> >> >> >> > File "aaa.py", line 5, in <module> >> >> > from ccc.ddd import sss >> >> > ImportError: No module named ccc.ddd >> >> >> >> > directory structure as follows: >> >> >> >> > ccc >> >> > | >> >> > ddd >> >> > | >> >> > aaa.py >> >> > sss.py >> >> >> >> A python file isn't importable unless the directory also contains a file >> >> named __init__.py . >> >> >> >> Try making __init__.py files in the ccc and ddd directories. If you >> >> don't know what to put in them, just leave them blank. >> >> >> It is having __init__.py as blank in ccc and ddd directories. But it still doesnot work. >> -- What directory are you in when you execute the script? Python doesn't look up for packages so if you're in ddd and calling "python aaa.py", Python doesn't know about the ccc package. You'd just import sss, or add the parent directory of ccc to sys.path.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-11 09:51 +0000 |
| Message-ID | <mailman.3877.1386755511.18130.python-list@python.org> |
| In reply to | #61528 |
On 11/12/2013 05:45, smilesonisamal@gmail.com wrote: > On Wednesday, December 11, 2013 10:23:34 AM UTC+5:30, John Gordon wrote: >> In <93405ea9-6faf-4a09-9fd9-ed264e3136e1@googlegroups.com> smilesonisamal@gmail.com writes: >> >> >> >>> File "aaa.py", line 5, in <module> >> >>> from ccc.ddd import sss >> >>> ImportError: No module named ccc.ddd >> >> >> >>> directory structure as follows: >> >> >> >>> ccc >> >>> | >> >>> ddd >> >>> | >> >>> aaa.py >> >>> sss.py >> >> >> >> A python file isn't importable unless the directory also contains a file >> >> named __init__.py . >> >> >> >> Try making __init__.py files in the ccc and ddd directories. If you >> >> don't know what to put in them, just leave them blank. >> >> >> It is having __init__.py as blank in ccc and ddd directories. But it still doesnot work. >> -- >> >> John Gordon Imagine what it must be like for a real medical doctor to >> >> gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'. > Have you actually written anything above? You also appear to be suffering from the highly contagious double spaced google disease. So would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2013-12-11 16:15 +0000 |
| Message-ID | <l8a33t$dhs$1@reader1.panix.com> |
| In reply to | #61528 |
In <58f7bd2a-ef82-4782-b4fb-db824f9c8e44@googlegroups.com> smilesonisamal@gmail.com writes: > > > File "aaa.py", line 5, in <module> > > > > > from ccc.ddd import sss > > > > > ImportError: No module named ccc.ddd > > > > > directory structure as follows: > > > > > ccc > > > | > > > ddd > > > | > > > aaa.py > > > sss.py > > It is having __init__.py as blank in ccc and ddd directories. But it > still doesnot work. What directory are you in when you run your python command? As written, your import will only work if you're in the parent directory of ccc (or that directory is in your PYTHONPATH.) -- John Gordon Imagine what it must be like for a real medical doctor to gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-12-10 22:02 -0700 |
| Message-ID | <mailman.3869.1386738181.18130.python-list@python.org> |
| In reply to | #61523 |
On 12/10/2013 09:25 PM, Michael Torrie wrote: > On 12/10/2013 08:56 PM, smilesonisamal@gmail.com wrote: >> Traceback (most recent call last): >> File "aaa.py", line 5, in <module> >> from ccc.ddd import sss >> ImportError: No module named ccc.ddd >> >> directory structure as follows: >> >> ccc >> | >> ddd >> | >> aaa.py >> sss.py > > This is because directories have no inherent meaning to python. A > module is normally a file. If you want to group a bunch of files > together you have to use a package. See the docs on how to make a > package. But the namespace structure within a package isn't based on > the directory tree either. It's usually set up by __init__.py within > the package which imports modules defined in the package into the > namespace. > > http://docs.python.org/3/tutorial/modules.html#packages > > Hope this helps. > I didn't quite get that right. Follow John's advice on __init.py__ and you'll have what you want I think.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web