469,621 Members | 1,678 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Python site-packages and import

(apologies for starting a new thread - Google can't retrieve the other
message for some reason)

Yes, /usr/lib/python/site-packages is in sys.path. This series of
commands should explain what I mean: I've put the Python ID3 module in
a sub-directory of site-packages as an illustration.

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/
ID3.py ID3.pyc ID3.pyo README apt_inst.so apt_pkg.so apt_proxy
bsddb3 debconf.py debconf.pyc debconf.pyo id3 pj twisted

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/apt_proxy/
__init__.py __init__.pyo apt_proxy.pyc apt_proxy_conf.py
apt_proxy_conf.pyo apt_proxytap.pyc memleak.py memleak.pyo
misc.pyc packages.py packages.pyo
__init__.pyc apt_proxy.py apt_proxy.pyo apt_proxy_conf.pyc
apt_proxytap.py apt_proxytap.pyo memleak.pyc misc.py
misc.pyo packages.pyc twisted_compat

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/id3
ID3.py ID3.pyc ID3.pyo

pzs@bonnie:~$ python
Python 2.3.5 (#2, Feb 9 2005, 00:38:15)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import sys
sys.path ['', '/usr/lib/python23.zip', '/usr/lib/python2.3',
'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk',
'/usr/lib/python2.3/lib-dynload',
'/usr/local/lib/python2.3/site-packages',
'/usr/lib/python2.3/site-packages'] import apt_proxy.memleak
import id3.ID3 Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named id3.ID3


Peter
Jul 19 '05 #1
2 5051
th*******@my-deja.com (Peter Saffrey) writes:
pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/id3
ID3.py ID3.pyc ID3.pyo
import id3.ID3 Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named id3.ID3


It is missing a file named "__init__.py" at
/usr/lib/python2.3/site-packages/id3

Without it Python won't consider "import id3" as valid (and consequently won't
import submodules as well).

Just 'touch' the file and try again.

--
Jorge Godoy <go***@ieee.org>
Jul 19 '05 #2
Peter Saffrey wrote:
(apologies for starting a new thread - Google can't retrieve the other
message for some reason)

Yes, /usr/lib/python/site-packages is in sys.path. This series of
commands should explain what I mean: I've put the Python ID3 module in
a sub-directory of site-packages as an illustration.

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/
ID3.py ID3.pyc ID3.pyo README apt_inst.so apt_pkg.so apt_proxy
bsddb3 debconf.py debconf.pyc debconf.pyo id3 pj twisted

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/apt_proxy/
__init__.py __init__.pyo apt_proxy.pyc apt_proxy_conf.py
apt_proxy_conf.pyo apt_proxytap.pyc memleak.py memleak.pyo
misc.pyc packages.py packages.pyo
__init__.pyc apt_proxy.py apt_proxy.pyo apt_proxy_conf.pyc
apt_proxytap.py apt_proxytap.pyo memleak.pyc misc.py
misc.pyo packages.pyc twisted_compat

pzs@bonnie:~$ ls /usr/lib/python2.3/site-packages/id3
ID3.py ID3.pyc ID3.pyo

pzs@bonnie:~$ python
Python 2.3.5 (#2, Feb 9 2005, 00:38:15)
[GCC 3.3.5 (Debian 1:3.3.5-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import sys
sys.path
['', '/usr/lib/python23.zip', '/usr/lib/python2.3',
'/usr/lib/python2.3/plat-linux2', '/usr/lib/python2.3/lib-tk',
'/usr/lib/python2.3/lib-dynload',
'/usr/local/lib/python2.3/site-packages',
'/usr/lib/python2.3/site-packages']
import apt_proxy.memleak
import id3.ID3


Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named id3.ID3


Peter


your site-package/id3 lacks a __init__.py file. '__init__.py' file can
be just an empty file but it needs to be there for python to be
considered as a package.

Alternatively, you can use 'from id3 import ID3' instead of 'import id3.ID3'

Cheers
Maurice
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Tim Parkin | last post: by
22 posts views Thread by mattf | last post: by
13 posts views Thread by Steven Bethard | last post: by
40 posts views Thread by =?iso-8859-1?B?QW5kcuk=?= | last post: by
reply views Thread by Chris Calloway | last post: by
7 posts views Thread by Michele Simionato | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.