Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

python - I get an error in python3 when importing mechanize

I get an error in python3 when importing mechanize.

I've just installed mechanize into my virtualenv where python3 is installed.

$ which python3
/Users/myname/.virtualenvs/python3/bin/python3

$ pip freeze
mechanize==0.2.5

But, when I try to import mechanize in my python code, I get this error.

import mechanize

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize

/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize/__init__.py in <module>()
    117 import sys
    118 
--> 119 from _version import __version__
    120 
    121 # high-level stateful browser-style interface

ImportError: No module named '_version'

Does anyone know how to fix this problem?

I'm new to python and I've been studying how to program in python these days.

Thanks for your help in advance!

update

I've installed mechanize for python3. Now, I have an another error.

In [1]: import mechanize
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize

/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/__init__.py in <module>()
    120 
    121 # high-level stateful browser-style interface
--> 122 from ._mechanize import 
    123      Browser, History, 
    124      BrowserStateError, LinkNotFoundError, FormNotFoundError

/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_mechanize.py in <module>()

/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_html.py in <module>()

ImportError: cannot import name _sgmllib_copy

I checked what I've installed in my working virtualenv. I found some warnings.

$ pip freeze
cssselect==0.9.1
httplib2==0.8
ipython==1.1.0
lxml==3.2.4
## FIXME: could not find svn URL in dependency_links for this package:
mechanize==0.2.6.dev-20140305
pyquery==1.2.8
Warning: cannot find svn location for mechanize==0.2.6.dev-20140305
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Alas, mechanize doesn't support Python 3. http://wwwsearch.sourceforge.net/mechanize/faq.html

Python 2.4, 2.5, 2.6, or 2.7. Python 3 is not yet supported.

You might like to comment on the issue at https://github.com/jjlee/mechanize/issues/96


Update: I wrote my own automating library MechanicalSoup. It's Python 3 compatible https://github.com/hickford/MechanicalSoup


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...