Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an error when importing mechanize branch for python3

I have installed mechanize library for python3. https://github.com/adevore/mechanize/tree/python3

But, when I import it, I get this error.

Python 3.3.3 (default, Dec 30 2013, 16:15:14) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import mechanize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/__init__.py", line 122, in <module>
  File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_mechanize.py", line 15, in <module>
  File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_html.py", line 16, in <module>
ImportError: cannot import name _sgmllib_copy

But, I'm sure that mechanize is installed in the same virtualenv directory.

$ pip freeze
## 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

I'm not used to operation in terminal, so I don't know how to fix this problem.

Could anyone please help me solve this problem?

Thank you in advance!

like image 304
crzyonez777 Avatar asked May 21 '26 12:05

crzyonez777


1 Answers

The git repository you referred to uses import wrong. The mechanize._html module imports _sgmllib_copy expecting to get mechanize._sgmllib_copy, but that way of doing imports has been deprecated in PEP 328. Rather it should be using relative imports, e.g. from . import _sgmllib_copy.

like image 197
Helmut Grohne Avatar answered May 24 '26 01:05

Helmut Grohne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!