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 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.
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.
Related
I am completely new to Python but I enjoyed it very much. I start with Python 2.7 before migrating to Python 3 since many applications for work have to do with Python 2.7.
I have quite sadly many version of python2.7 on my MacBook. One from Apple, one from Homebrew, one from Anaconda. I have pip version 18.0 installed.
I wanted to install many modules (scipy in particular) and I ran into the following problem.
On the console:
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
I get the error message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 130, in
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in
from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache
I looked on the web and found the solution for that by typing:
pip install --user matplotlib
Now when I do:
>>> import matplotlib
I get the message:
Traceback (most recent call last):
File "", line 1, in
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/init.py", line 126, in
from . import cbook
ImportError: cannot import name cbook
There is a confusion on the web about how to solve this problem. Is there still hope I can get back running?
I have a python script for auto mailing when there is a commit in svn, but when i run the script it gives following error :
Traceback (most recent call last):
File "E:\AutoSms-Svn-Repo\test-repo-is\hooks\mailer.py", line 41, in <module>
import svn.fs
File "C:\Python25\Lib\site-packages\svn\fs.py", line 19, in <module>
from libsvn.fs import *
File "C:\Python25\Lib\site-packages\libsvn\fs.py", line 5, in <module>
import _fs
ImportError: DLL load failed: The specified module could not be found.
I even added required path variables for dependent dlls and python path
but still i get this message, even from command prompt
Thanks in advance
I got the same problem instaling subversion under Windows 7 for Python 2.7.
The solution is simple and has been tested. (but hard work to find and analize)
Download and install binaries from Subversion
Make sure thet binaries folder (default: c:\Program Files (x86)\subversion\bin) is in your PATH system
Download Python files from site mentioned in point 1 ( Subversion )
Extract libsvn and svn into Python's site-packages folder
Open cmd (Window's command line console) and type: python. Then try to import svn module.
It should looks like (no error occured):
C:\>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from svn import core
>>>
I cant import rdflib in python. error detailed:
Python 2.7.3 (default, Jun 27 2012, 23:48:21)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rdflib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/rdflib/__init__.py", line 65, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "/usr/local/lib/python2.7/site-packages/rdflib/term.py", line 49, in <module>
from isodate import parse_time, parse_date, parse_datetime
ImportError: No module named isodate
I would be grateful if anybody can help.
Thanks.
If you actually install rdflib via pip, then its dependencies will come along with it (isodate included):
pip install -U rdflib
or
easy_install -U rdflib
Chances are you might have installed it directly from source, meaning you would have to take care of the deps yourself.
Information on installing pip if you dont have it already:
http://www.pip-installer.org/en/latest/installing.html
If you have easy_install, you can do: easy_install pip
It seems there is a dependency to isodate, so try installing that via your favorite PyPI-Installer (pip oder *easy_install*).
When I attempt to run the script below in Eclipse(PyDev):
import subprocess
subprocess.call("/usr/local/bin/mitmdump")
An error is returned:
Traceback (most recent call last):
File "/usr/local/bin/mitmdump", line 19, in <module>
from libmproxy import proxy, dump, cmdline
File "/Library/Python/2.7/site-packages/libmproxy/proxy.py", line 22, in <module>
import shutil, tempfile, threading
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 34, in <module>
from random import Random as _Random
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
If I run the same script from the bash, it works fine. What gives?
$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call("/usr/local/bin/mitmdump")
127.0.0.1 GET http://google.com/
There seems to be a related problem with Ubuntu Python ImportError cannot import urandom Since Ubuntu 12.04 upgrade but my environment is OSX.
To properly diagnose that, do the following:
Edit /usr/local/bin/mitmdump, and make:
try:
from libmproxy import proxy, dump, cmdline
except ImportError:
import sys
print 'Executable:', sys.executable
print '\n'.join(sorted(sys.path))
raise
And then check if what you're seeing is actually what you expected... (you can do those same prints in the command line to when the exception is not raised and check what's the difference and then, probably, update your PYTHONPATH inside Eclipse/PyDev).
I had the same symptoms but in python proper on the command line in Mac OS X. Found the answer here: Python: cannot import urandom module (OS X)
Not sure if it's the same problem you're having or how to invoke hash -r from Eclipse.
I would imagine your python path is net set properly. If so, python can't find the model and therefore can't import.
I am using macports to install various modules. Generally this works well, but below is an error I am getting that I am not easily resolving:
$ python
Python 2.6.6 (r266:84292, Feb 12 2011, 16:57:53)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns
>>> import opcode
>>> from dns import resolver
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/resolver.py", line 26, in <module>
import dns.message
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/message.py", line 28, in <module>
import dns.opcode
ImportError: No module named opcode
Could this be a path issue?
>>> import sys
>>> sys.path
['', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
$ cat /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/dns/init.py
[snipped comments]
# init.py for DNS class.
__version__ = '2.3.3'
import Type,Opcode,Status,Class
from Base import DnsRequest, DNSError
from Lib import DnsResult
from Base import *
from Lib import *
Error=DNSError
from lazy import *
Request = DnsRequest
Result = DnsResult
Thanks in advance.
Because you need to do:
from dns import resolver
This doesn't work:
import datetime.datetime
But this does:
from datetime import datetime
If you're importing a package that is part of another package, you need to use the "from" syntax
I uninstalled py26-dnspython and reinstalled. Problem solved. Fink on freenode made the suggestion. Thanks.
I am using Python 3.7 and I installed pubdns. This resolved my problem.
I faced extreme difficulty in using py3dns, pyDNS (won't install), dnspython and many more