Python site-packages and import

P

Peter Saffrey

(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.['', '/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']Traceback (most recent call last):



Peter
 
J

Jorge Godoy

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

Traceback (most recent call last):

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.
 
M

Maurice LING

Peter said:
(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.

['', '/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']

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top