He Jibo,

(my first name is Harald :) )

so, your problem is with importing _elementpath

there are 2 solutions, one at:

http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules

and the other at:
http://codespeak.net/pipermail/lxml-dev/2007-August/002906.html

The second one explains what is going wrong:
The tool that searches for the
modules is called modulefinder and is a part of the standard library.
Modulefinder is unable to find _elementpath.* because it is only imported
from the C code.

This is usually the base of the problem if py2exe fails to produce a working programm: some module is not found to be included while the script is checked. (Which is not THAT surprising considering what dynamic possibilities Pyton offers )
Solution is allways similiar: Just import the not found script manually within the main script; or have something like "import fakeimportsforpy2exe" within you main script and store all fake imports there.
Does this solve your problem?

Best wishes,

Harald


On Sat, Dec 4, 2010 at 16:29, He Jibo <hejibo@gmail.com> wrote:
Dear Massa,

The whole project does not have any error. It just does not have no  response. I tracked down that it are The following modules are causing problem.

from mechanize import Browser

from lxml import etree

from pyquery import PyQuery as pq

Then I tried your methods, it does not work. I just try to compile a very simple code using pyquery. It gave me some error. Below is the error message. It seems it is lxml caused the problem. I have attached my code and setup.py with the email. Thanks so much for your great help.

Traceback (most recent call last):
  File "Parser2.py", line 2, in <module>
  File "pyquery\__init__.pyc", line 10, in <module>
  File "pyquery\pyquery.pyc", line 6, in <module>
  File "pyquery\cssselectpatch.pyc", line 6, in <module>
  File "lxml\cssselect.pyc", line 8, in <module>
  File "lxml\etree.pyc", line 12, in <module>
  File "lxml\etree.pyc", line 10, in __load
  File "lxml.etree.pyx", line 39, in lxml.etree (src/lxml/lxml.etree.c:144751)
ImportError: No module named _elementpath




# -*- coding: utf-8 -*-

from pyquery import PyQuery as pq
import time

import urllib
import BeautifulSoup
import re


--------------Parser2.py---------------------------
class Parser():
    def __init__(self,url_link):
        self.url=url_link  

        self.title=""
       
 
    def connect(self):
        '''1 for connection success, 0 for connection error'''
        connectTrial=0
        while connectTrial<4:
            try:
                self.data = pq(url=self.url)               
                meta = self.data.find('meta')
                for i in range(len(meta)):
                    aMeta=meta.eq(i)
                    if 'description' == aMeta.attr('name'):
                        self.description = aMeta.attr('content')
   
                    if 'keywords' == aMeta.attr('name'):
                        self.keywords = aMeta.attr('content')
                break
            except:
                connectTrial=connectTrial+1
                time.sleep(0.5)
                print 'remote server does not respond. please try it later.'
        if connectTrial<4:
            return 1
        else:
            return 0
       

    def getTitle(self):
        title = self.data('title').text()
        if title:
            return title
        else:
            return ' '



if __name__ == "__main__":  
#    url_link = 'http://info.shoes.hc360.com/list/shoes_shiz.shtml'
    url_link = 'http://www.cctvhotdeals.com'
    a =  Parser(url_link)
    if a.connect():
        print a.getTitle()
    else:
        print 'connection failure.'


-----------------setup.py-----------

'''
http://web.archiveorange.com/archive/v/5H3d11fesgvZXKvrYblh
'''
# Used successfully in Python2.5 with matplotlib 0.91.2 and PyQt4 (and Qt 4.3.3)
from distutils.core import setup
import py2exe
#import mechanize


# We need to import the glob module to search for all files.
import glob

# We need to exclude matplotlib backends not being used by this executable.  You may find
# that you need different excludes to create a working executable with your chosen backend.
# We also need to include include various numerix libraries that the other functions call.

opts = {
    'py2exe': { "includes" : ["sip"],
                'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg',
                             '_fltkagg', '_gtk', '_gtkcairo', ],
                'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                 'libgobject-2.0-0.dll'],
                #'packages': ['mechanize'],

              }
       }

# Save matplotlib-data to mpl-data ( It is located in the matplotlib\mpl-data
# folder and the compiled programs will look for it in \mpl-data
# note: using matplotlib.get_mpldata_info


# for console program use 'console = [{"script" : "scriptname.py"}]
setup(name="Link Validator 1.2",
      version="1.1",
      description = " Link Validator 1.2",

      author="He, Jibo",
      author_email="hejibo@gmail.com",
      url="http://goldenclickonline.appspot.com",
#      zipfile = True,
      windows=[{"script" : "Parser2.py",'icon_resources':[(1,"LinkValidator.ico")]}], options=opts)


---------------------------
He Jibo
Department of Psychology,
Beckman Institute for Advanced Science and Technology
University of Illinois, Urbana Champaign,
603 East Daniel St.,
Champaign, IL 61820
website: www.hejibo.info



On Sat, Dec 4, 2010 at 9:12 AM, Massa, Harald Armin <chef@ghum.de> wrote:
To give you more help, can you please exactly paste the error you are getting?

There should be something like

<yourappname>.exe.log 

besides the .exe file

Harald


On Sat, Dec 4, 2010 at 16:10, He Jibo <hejibo@gmail.com> wrote:
Thanks so much for your help, but I still could not import mechanize and pyquery. Any other solutions?
---------------------------
He Jibo
Department of Psychology,
Beckman Institute for Advanced Science and Technology
University of Illinois, Urbana Champaign,
603 East Daniel St.,
Champaign, IL 61820
website: www.hejibo.info




On Sat, Dec 4, 2010 at 4:26 AM, Massa, Harald Armin <chef@ghum.de> wrote:
Hello He Jibo,

from mechanize import Browser

from lxml import etree

from pyquery import PyQuery as pq


from xxx ximport yyyy often fails when py2exed.

Workaround is:

import mechanize
from mechanize import Browser
 
import the whole model via import first; then grab single names. Also possible:

import mechanize
Browser = mechanize.Browser

Harald

--
GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607

Amtsgericht Stuttgart, HRB 734971
-
persuadere.
et programmare




--
GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607

Amtsgericht Stuttgart, HRB 734971
-
persuadere.
et programmare




--
GHUM GmbH
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607

Amtsgericht Stuttgart, HRB 734971
-
persuadere.
et programmare