I have a clean install of Python 3.3.2 on Windows 7. I'm trying to import html.parser.HTMLParser, using the example from the documentation: Simple HTML and XHTML parser
But I'm getting the error:
>>> from html.parser import HTMLParser
aee4
gg2
Traceback (most recent call last):
File "htmlang.py", line 1, in <module>
from html.parser import HTMLParser
File "c:\Python33\lib\html\parser.py", line 13, in <module>
import warnings
File "c:\Python33\lib\warnings.py", line 6, in <module>
import linecache
File "c:\Python33\lib\linecache.py", line 10, in <module>
import tokenize
File "c:\Python33\lib\tokenize.py", line 37, in <module>
__all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
AttributeError: 'module' object has no attribute '__all__'
I have just opened the interpreter and typed the import line. Why it isn't working as expected? Why it is printing the weird "aee4" and "gg2" strings?
Just write "import HTMLParser" and it will work
Related
I installed the requests package, but when I start to use it, I got this error :
AttributeError: 'module' object has no attribute 'get'
This my code :
from bs4 import BeautifulSoup
import requests
r = requests.get("http://someSite.com/path")
I checked some solution to this problem, and most of them saying that either there is a mistake with importing the package, or that a file with the name requests.py exist in the current directory, but it's not the case for me.
it's been a while since I got this error, and I stuck with it.
any idea? thanks.
UPDATE
FULL error message
Traceback (most recent call last):
File "parser.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 47, in <module>
from cryptography import x509
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/usr/local/lib/python2.7/dist-packages/cryptography/x509/base.py", line 14, in <module>
from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/asymmetric/rsa.py", line 14, in <module>
from cryptography.hazmat.backends.interfaces import RSABackend
File "/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
import pkg_resources
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 76, in <module>
import parser
File "/home/lichiheb/Desktop/parser.py", line 4, in <module>
r = requests.get("http://t...content-available-to-author-only...s.com/search-results-jobs/?searchId=1483197031.949&action=search&page=1&view=list")
AttributeError: 'module' object has no attribute 'get'
Your file is called parser.py which conflicts with a built-in module name parser.
The error message about requests was a weird and unfortunate coincidence. Just rename your module to something else.
I'm new with Python and NLTK
When I test the following lines in the Python console
import nltk.data
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
text ="toto. titi. tutu"
tokens = tokenizer.tokenize(text)
print(tokens)
I get what I expect. But when I execute these lines from a file, for example with the command line > python tokenize.py, I get errors:
C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\python.exe C:/Documents/Dvpt/SemanticAndOpenData/scholar/scholar.py/tokenize.py
Traceback (most recent call last):
File "C:/Documents/Dvpt/SemanticAndOpenData/scholar/scholar.py/tokenize.py", line 1, in <module>
import nltk.data
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\__init__.py", line 89, in <module>
from nltk.internals import config_java
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\internals.py", line 11, in <module>
import subprocess
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\subprocess.py", line 395, in <module>
import threading
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\threading.py", line 10, in <module>
from traceback import format_exc as _format_exc
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\traceback.py", line 3, in <module>
import linecache
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\linecache.py", line 10, in <module>
import tokenize
File "C:\Documents\Dvpt\SemanticAndOpenData\scholar\scholar.py\tokenize.py", line 2, in <module>
tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\data.py", line 786, in load
resource_val = pickle.load(opened_resource)
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\tokenize\__init__.py", line 63, in <module>
from nltk.tokenize.simple import (SpaceTokenizer, TabTokenizer, LineTokenizer,
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\tokenize\simple.py", line 38, in <module>
from nltk.tokenize.api import TokenizerI, StringTokenizer
File "C:\outils\Python\WinPython-64bit-3.4.3.5\python-3.4.3.amd64\lib\site-packages\nltk\tokenize\api.py", line 13, in <module>
from nltk.internals import overridden
ImportError: cannot import name 'overridden'
Process finished with exit code 1
And I'm stuck on the problem and I can't find a way to solve it. Thanks in advance for any useful proposal.
You need to name the script something other than tokenize.py
The problem here is that you have named your script as tokenize.py. Try renaming the file to something like my_tokenizer.py. Actually what is happening is that when you are using
import tokenize
What it is doing is trying to import the current file itself and thus you are getting the errors.
I'm using Pyshark and Python 2.6 on OS X 10.10. I simply try to import pyshark in my code, and this error is thrown. Any idea of what could be going wrong?
/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 "/Users/spencergardner/Google Drive/development/python-sockets/sniff.py"
Traceback (most recent call last):
File "/Users/spencergardner/Google Drive/development/python-sockets/sniff.py", line 1, in <module>
import pyshark
File "/Library/Python/2.6/site-packages/pyshark/__init__.py", line 1, in <module>
from pyshark.capture.live_capture import LiveCapture
File "/Library/Python/2.6/site-packages/pyshark/capture/live_capture.py", line 1, in <module>
from pyshark.capture.capture import Capture
File "/Library/Python/2.6/site-packages/pyshark/capture/capture.py", line 12, in <module>
from pyshark.tshark.tshark_xml import packet_from_xml_packet, psml_structure_from_xml
File "/Library/Python/2.6/site-packages/pyshark/tshark/tshark_xml.py", line 5, in <module>
from pyshark.packet.layer import Layer
File "/Library/Python/2.6/site-packages/pyshark/packet/layer.py", line 57
return {slot: getattr(self, slot) for slot in self.__slots__}
^
SyntaxError: invalid syntax
The error is due to using a dictionary comprehension, a language feature that was introduced to Python 2 in 2.7, not the 2.6 you're trying to use. Apple ships OS X 10.10 with both 2.7 and 2.6. Is there a reason you can't use 2.7 instead?
I have a script which requires multiprocessing. What I found from this script is that there is a problem with the multiprocessing module. To test this theory, I copied and pasted
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
into a test script and received the following traceback
Traceback (most recent call last):
File "a.py", line 1, in <module>
from multiprocessing import Process
File "/usr/lib64/python3.3/multiprocessing/__init__.py", line 40, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib64/python3.3/multiprocessing/util.py", line 16, in <module>
import threading # we want threading to install it's
File "/usr/lib64/python3.3/threading.py", line 11, in <module>
from traceback import format_exc as _format_exc
File "/usr/lib64/python3.3/traceback.py", line 3, in <module>
import linecache
File "/usr/lib64/python3.3/linecache.py", line 10, in <module>
import tokenize
File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
from django.conf import settings
File "/usr/lib/python3.3/site-packages/django/conf/__init__.py", line 9, in <module>
import logging
File "/usr/lib64/python3.3/logging/__init__.py", line 195, in <module>
_lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'
Also, I am running fedora 18 64-bit on a quad core ivy bridge. Why am I receiving this traceback error?
Suggestion
Here is what happens when I run RLock
$ python3
>>> import threading
>>> threading.RLock()
<_thread.RLock owner=0 count=0>
>>>
File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
from django.conf import settings
Your /home/lucas/Server/ClinApp/weblabs/utils/token.py script is being imported instead of the standard python 'token.py'. Its got a bug in it or it simply shouldn.t be imported as a top level script. You probably have /home/lucas/Server/ClinApp/weblabs/utils/ in your python path in some way.
Generally, its not a good idea to name python scripts after builtin scripts.
After you rename token.py to something else (get_token.py), remember to delete token.pyc in your local working directory. Or else, you will continue to get the Traceback error message you listed above.
System : XP, work with python 2.7
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import json
File "C:\Python27\ArcGIS10.1\lib\json\__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "C:\Python27\ArcGIS10.1\lib\json\decoder.py", line 7, in <module>
from json import scanner
ImportError: cannot import name scanner
Anyone can explain me how to manage this error please ???
this morning I haven't got this problem, but this afternoon my script won't work ((
I think this is caused by relative import path,
File "C:\Python27\ArcGIS10.1\lib\json\decoder.py", line 7,
from json import scanner
it's trying to import scanner from
C:\Python27\ArcGIS10.1\lib\json