简体   繁体   中英

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!

The git repository you referred to uses import wrong. The mechanize._html module import s _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, eg from . import _sgmllib_copy from . import _sgmllib_copy .

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 from . import _beautifulsoup seems to be working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM