3

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!

crzyonez777
  • 1,789
  • 4
  • 18
  • 27

2 Answers2

2

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.

Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67
1

https://github.com/adevore/mechanize/tree/python3

This branch doesn't contain _sgmllib_copy.py at all. I took this file from master branch (it needs to change print smth to print (smth)). But I still don't get how import should be used. In _html.py module (it's located in mechanize folder) used

from . import _sgmllib_copy as sgmllib

Is this wrong? But from . import _beautifulsoup seems to be working.

  • Thank you for your help!! I added _sqmllib_copy from master branch and reinstalled it. Now I have this error "IndentationError: unexpected indent"... – crzyonez777 Mar 19 '14 at 08:23
  • So you can fix this error in source file. Is it showing line number where it occurs? Or you can try to use my fix https://drive.google.com/file/d/0B2tqHfR7_fJua2pwNUFmSDlIWnM/edit?usp=sharing It installs but still doesn't work for me – Maxim Kharin Mar 19 '14 at 10:49