Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[resolved][python program issue] "No module named expat"
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
terree
n00b
n00b


Joined: 26 Oct 2007
Posts: 12

PostPosted: Fri Apr 19, 2013 12:07 pm    Post subject: [resolved][python program issue] "No module named expat Reply with quote

Hi all,
I just want to write a py program using ElementTree to parse my config file.
My code is like this:
Code:

import sys
import os
from xml.etree import ElementTree as et


def test():
  Xmlcfg = et.ElementTree(file = 'test.xml').getroot()
  name = Xmlcfg.find('aa').text
  return 1

if __name__ == "__main__":
   ret = test()
   sys.exit(ret)


But when i run it, the Python reported this error:
Code:

oppo@localhost ~ $ python test.py
Traceback (most recent call last):
  File "test.py", line 15, in <module>
    ret = test()
  File "test.py", line 10, in test
    Xmlcfg = et.ElementTree(file = 'test.xml').getroot()
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 611, in __init__
    self.parse(file)
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 651, in parse
    parser = XMLParser(target=TreeBuilder())
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1466, in __init__
    "No module named expat; use SimpleXMLTreeBuilder instead"
ImportError: No module named expat; use SimpleXMLTreeBuilder instead


Please help me to resolve it.
Thanks!

This may be useful infomation for you to help me.

localhost ~ # eselect python list
Available Python interpreters:
[1] python2.7 *
[2] python3.2

When I use python 3.2 to run this script, it's Ok.
This is what I've tried to located the expat module:
Code:

localhost ~ # find . /usr/lib64/python2.7/  -iname 'expat*'
/usr/lib64/python2.7/xml/sax/expatreader.pyo
/usr/lib64/python2.7/xml/sax/expatreader.py
/usr/lib64/python2.7/xml/sax/expatreader.pyc
/usr/lib64/python2.7/xml/parsers/expat.py
/usr/lib64/python2.7/xml/parsers/expat.pyc
/usr/lib64/python2.7/xml/parsers/expat.pyo
/usr/lib64/python2.7/xml/dom/expatbuilder.pyo
/usr/lib64/python2.7/xml/dom/expatbuilder.py
/usr/lib64/python2.7/xml/dom/expatbuilder.pyc

localhost ~ # find . /usr/lib64/python3.2/  -iname 'expat*'
/usr/lib64/python3.2/xml/sax/expatreader.py
/usr/lib64/python3.2/xml/sax/__pycache__/expatreader.cpython-32.pyc
/usr/lib64/python3.2/xml/sax/__pycache__/expatreader.cpython-32.pyo
/usr/lib64/python3.2/xml/parsers/expat.py
/usr/lib64/python3.2/xml/parsers/__pycache__/expat.cpython-32.pyc
/usr/lib64/python3.2/xml/parsers/__pycache__/expat.cpython-32.pyo
/usr/lib64/python3.2/xml/dom/expatbuilder.py
/usr/lib64/python3.2/xml/dom/__pycache__/expatbuilder.cpython-32.pyo
/usr/lib64/python3.2/xml/dom/__pycache__/expatbuilder.cpython-32.pyc

localhost ~ # cat /usr/lib64/python2.7/xml/parsers/expat.py
"""Interface to the Expat non-validating XML parser."""
__version__ = '$Revision: 17640 $'

from pyexpat import *

localhost ~ # find . /usr/lib64/python2.7/  -iname 'pyexpat*'

localhost ~ # find . /usr/lib64/python3.2/  -iname 'pyexpat*'
/usr/lib64/python3.2/lib-dynload/pyexpat.cpython-32.so



I Can't find any lib named pyexpat, but from python3.2 it's there. Is that the reason for my issue?


My Method of resolving:
1. delete build in my global USE(make.conf) and make other change of it.
2. emerge --update --deep --newuse world
3. emerge --depclean
4. revdep-rebuild

Thanks.


Last edited by terree on Sat Apr 20, 2013 8:41 am; edited 2 times in total
Back to top
View user's profile Send private message
megabaks
Apprentice
Apprentice


Joined: 22 Jan 2012
Posts: 237
Location: Russia && Saint-Petersburg

PostPosted: Fri Apr 19, 2013 1:30 pm    Post subject: Reply with quote

Code:
ls -lh /usr/lib*/python*/xml/parsers/expat.py

_________________
sorry my bad english
Back to top
View user's profile Send private message
terree
n00b
n00b


Joined: 26 Oct 2007
Posts: 12

PostPosted: Fri Apr 19, 2013 1:36 pm    Post subject: Reply with quote

megabaks wrote:
Code:
ls -lh /usr/lib*/python*/xml/parsers/expat.py


Thanks for your reply.

These files are like this:
localhost ~ # ls -lh /usr/lib*/python*/xml/parsers/expat.py
-rw-r--r-- 1 root root 114 Apr 16 23:56 /usr/lib/python2.7/xml/parsers/expat.py
-rw-r--r-- 1 root root 276 Mar 21 12:12 /usr/lib/python3.2/xml/parsers/expat.py
-rw-r--r-- 1 root root 114 Apr 16 23:56 /usr/lib64/python2.7/xml/parsers/expat.py
-rw-r--r-- 1 root root 276 Mar 21 12:12 /usr/lib64/python3.2/xml/parsers/expat.py

And this is my emerge --info:
Code:

localhost ~ # emerge --info
Portage 2.1.11.55 (default/linux/amd64/13.0/desktop, gcc-4.6.3, glibc-2.15-r3, 3.7.10-gentoo x86_64)
=================================================================
System uname: Linux-3.7.10-gentoo-x86_64-Intel-R-_Core-TM-2_Quad_CPU_Q9650_@_3.00GHz-with-gentoo-2.1
KiB Mem:     1307812 total,   1051340 free
KiB Swap:    1048572 total,   1048572 free
Timestamp of tree: Thu, 11 Apr 2013 00:45:01 +0000
ld GNU ld (GNU Binutils) 2.22
app-shells/bash:          4.2_p37
dev-lang/python:          2.7.3-r3, 3.2.3-r2
dev-util/cmake:           2.8.9
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.1-r1
sys-apps/openrc:          0.11.8
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.69
sys-devel/automake:       1.10.3, 1.11.6
sys-devel/binutils:       2.22-r1
sys-devel/gcc:            4.6.3
sys-devel/gcc-config:     1.7.3
sys-devel/libtool:        2.4-r1
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.6 (virtual/os-headers)
sys-libs/glibc:           2.15-r3
Repositories: gentoo
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirrors.163.com/gentoo/ http://mirrors.sohu.com/gentoo/ ftp://mirrors.stuhome.net/gentoo/ rsync://mirrors.stuhome.net/gentoo/ http://mirrors.stuhome.net/gentoo/ rsync://mirrors.xmu.edu.cn/gentoo/ http://mirrors.xmu.edu.cn/gentoo ftp://mirrors.xmu.edu.cn/gentoo http://mirror.mcs.anl.gov/pub/gentoo/ http://www.gtlib.gatech.edu/pub/gentoo"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="a52 aac acl acpi alsa amd64 atm berkdb bindist bluetooth branding build bzip2 cairo cdda cdr cli consolekit cracklib crypt cups cxx dbus deprecated dri dts dvd dvdr emacs emboss encode exif fam fbcon fbcondecor firefox flac fortran gdbm gif gpm gtk iconv ipv6 jpeg lcms ldap libnotify mad mmx mng modules mp3 mp4 mpeg mudflap multilib ncurses nls nptl nptlonly ogg opengl openmp pam pango pcre pdf png policykit ppds qt3support qt4 readline sdl session socks5 spell sse sse2 ssl startup-notification svg tcpd tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 xcb xml xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-3" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="fbdev glint intel mach64 mga nouveau nv r128 radeon savage sis tdfx trident vesa via vmware dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Back to top
View user's profile Send private message
megabaks
Apprentice
Apprentice


Joined: 22 Jan 2012
Posts: 237
Location: Russia && Saint-Petersburg

PostPosted: Fri Apr 19, 2013 2:11 pm    Post subject: Reply with quote

hmmm...
what interpreter you try use?
or how you trying run you script...
_________________
sorry my bad english
Back to top
View user's profile Send private message
terree
n00b
n00b


Joined: 26 Oct 2007
Posts: 12

PostPosted: Fri Apr 19, 2013 3:21 pm    Post subject: Reply with quote

megabaks wrote:
hmmm...
what interpreter you try use?
or how you trying run you script...


I was using Python 2.7 as the interpreter.
Just create a python script, name test.py. Then run it by this shell command:
Code:

python test.py


Do I understand what you mean?
If not, please let me know.

Thanks.
Back to top
View user's profile Send private message
terree
n00b
n00b


Joined: 26 Oct 2007
Posts: 12

PostPosted: Fri Apr 19, 2013 3:32 pm    Post subject: Reply with quote

megabaks wrote:
hmmm...
what interpreter you try use?
or how you trying run you script...


I was running it in a VMware machine and I gave it about 1000M memory and 2 cpu cores.

Regards!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum