New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'module' object has no attribute 'init' #59

Closed
Linux-oiD opened this Issue May 12, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@Linux-oiD

Linux-oiD commented May 12, 2016

Trying to use this module on Windows with Python 3.4 and CentOS with Python 3.3:

Python 3.3.3 (default, Mar 9 2016, 14:47:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.

import graphitesend as gr
g = gr.init()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'init'

Module's dictionary:

print(gr.dict)
{'doc': None, 'cached': '/usr/local/lib/python3.3/site-packages/graphitesend/pycache/init.cpython-33.pyc', 'loader': <_frozen_importlib.SourceFileLoader object at 0x7fb398ce5550>, 'path': ['/usr/local/lib/python3.3/site-packages/graphitesend'], 'file': '/usr/local/lib/python3.3/site-packages/graphitesend/init.py', 'name': 'graphitesend', 'builtins': {'exec': , 'MemoryError': <class 'MemoryError'>, 'id': , 'callable': , 'RuntimeWarning': <class 'RuntimeWarning'>, 'PermissionError': <class 'PermissionError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'Warning': <class 'Warning'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'hasattr': , 'copyright': Copyright (c) 2001-2013 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
All Rights Reserved., 'int': <class 'int'>, 'ord': , 'slice': <class 'slice'>, 'dict': <class 'dict'>, 'SystemError': <class 'SystemError'>, 'min': , 'TypeError': <class 'TypeError'>, 'AttributeError': <class 'AttributeError'>, 'SyntaxError': <class 'SyntaxError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'bytearray': <class 'bytearray'>, 'IOError': <class 'OSError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'name': 'builtins', 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'complex': <class 'complex'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'super': <class 'super'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'locals': , 'help': Type help() for interactive help, or help(object) for help about object., 'next': , 'all': , 'SyntaxWarning': <class 'SyntaxWarning'>, 'hex': , 'enumerate': <class 'enumerate'>, 'license': Type license() to see the full license text, 'classmethod': <class 'classmethod'>, 'NotImplemented': NotImplemented, 'import': , 'zip': <class 'zip'>, 'input': , 'BytesWarning': <class 'BytesWarning'>, 'TimeoutError': <class 'TimeoutError'>, 'delattr': , 'KeyError': <class 'KeyError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'bytes': <class 'bytes'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'doc': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the nil' object; Ellipsis represents...' in slices.", 'build_class': , 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'NameError': <class 'NameError'>, 'property': <class 'property'>, 'memoryview': <class 'memoryview'>, 'len': , 'FutureWarning': <class 'FutureWarning'>, 'EOFError': <class 'EOFError'>, 'chr': , 'debug': True, 'BufferError': <class 'BufferError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'frozenset': <class 'frozenset'>, 'sum': , 'pow': , 'compile': , 'FloatingPointError': <class 'FloatingPointError'>, 'False': False, 'SystemExit': <class 'SystemExit'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'package': None, 'RuntimeError': <class 'RuntimeError'>, 'ascii': , 'object': <class 'object'>, 'UnicodeError': <class 'UnicodeError'>, 'ImportError': <class 'ImportError'>, 'format': , 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'loader': <class '_frozen_importlib.BuiltinImporter'>, 'dir': , 'ArithmeticError': <class 'ArithmeticError'>, 'bin': , 'float': <class 'float'>, 'BlockingIOError': <class 'BlockingIOError'>, 'ChildProcessError': <class 'ChildProcessError'>, 'tuple': <class 'tuple'>, 'TabError': <class 'TabError'>, 'list': <class 'list'>, 'isinstance': , 'IsADirectoryError': <class 'IsADirectoryError'>, 'staticmethod': <class 'staticmethod'>, 'AssertionError': <class 'AssertionError'>, 'IndentationError': <class 'IndentationError'>, 'IndexError': <class 'IndexError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'ConnectionError': <class 'ConnectionError'>, 'True': True, 'hash': , 'print': , 'range': <class 'range'>, 'ResourceWarning': <class 'ResourceWarning'>, 'EnvironmentError': <class 'OSError'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'oct': , 'getattr': , 'globals': , 'setattr': , 'UnicodeWarning': <class 'UnicodeWarning'>, 'filter': <class 'filter'>, 'reversed': <class 'reversed'>, 'sorted': , 'UserWarning': <class 'UserWarning'>, 'InterruptedError': <class 'InterruptedError'>, 'open': , 'FileExistsError': <class 'FileExistsError'>, 'any': , 'bool': <class 'bool'>, 'ReferenceError': <class 'ReferenceError'>, 'map': <class 'map'>, 'BaseException': <class 'BaseException'>, 'NotImplementedError': <class 'NotImplementedError'>, 'repr': , 'OverflowError': <class 'OverflowError'>, 'vars': , 'max': , 'ImportWarning': <class 'ImportWarning'>, 'LookupError': <class 'LookupError'>, 'round': , 'type': <class 'type'>, 'Exception': <class 'Exception'>, 'Ellipsis': Ellipsis, 'str': <class 'str'>, 'GeneratorExit': <class 'GeneratorExit'>, 'StopIteration': <class 'StopIteration'>, 'None': None, 'ValueError': <class 'ValueError'>, 'abs': , 'eval': , 'divmod': , 'set': <class 'set'>, 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
for supporting Python development. See www.python.org for more information., 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'OSError': <class 'OSError'>, 'iter': , 'issubclass': }, 'package': 'graphitesend', 'initializing': False}

fetzerch added a commit to fetzerch/atMETEO that referenced this issue Jun 19, 2016

tools: Update weather_station.py to Python 3.5
Update to Python 3.5 and fix errors:
- C0411: standard import "import X" comes before "import serial"
- Fix version of graphitesend to 0.3.4, as newer ones fail with
  "AttributeError: 'module' object has no attribute 'init'"
  (daniellawrence/graphitesend#59)
@benhoyt

This comment has been minimized.

Show comment
Hide comment
@benhoyt

benhoyt Jul 21, 2016

Yeah, I'm running into this issue too -- it's a Python 3.x problem I believe, and __init__.py should be changed to use a relative import like so (note the dot):

from .graphitesend import *

benhoyt commented Jul 21, 2016

Yeah, I'm running into this issue too -- it's a Python 3.x problem I believe, and __init__.py should be changed to use a relative import like so (note the dot):

from .graphitesend import *
@benhoyt

This comment has been minimized.

Show comment
Hide comment
@benhoyt

benhoyt Jul 21, 2016

@Linux-oiD Okay, I guess this library isn't Python 3 ready yet. When I work around the above, the next error is this:

Traceback (most recent call last):
  File "/Users/bhoyt/Envs/scip/lib/python3.5/site-packages/graphitesend/graphitesend.py", line 260, in _dispatch_send
    sending_function(message.encode("ascii"))
  File "/Users/bhoyt/Envs/scip/lib/python3.5/site-packages/graphitesend/graphitesend.py", line 291, in _send
    self.socket.sendall(message.encode("ascii"))
AttributeError: 'bytes' object has no attribute 'encode'

What's happening is that it's doing a double-encode: _dispatch_send() is calling message.encode('ascii'), producing a bytes object, and then _send() tries to encode to ASCII again. Which is allowed on Python 2 but fails with the above on Python 3 due to the latter's stricter unicode/bytes handling. Oh well...

benhoyt commented Jul 21, 2016

@Linux-oiD Okay, I guess this library isn't Python 3 ready yet. When I work around the above, the next error is this:

Traceback (most recent call last):
  File "/Users/bhoyt/Envs/scip/lib/python3.5/site-packages/graphitesend/graphitesend.py", line 260, in _dispatch_send
    sending_function(message.encode("ascii"))
  File "/Users/bhoyt/Envs/scip/lib/python3.5/site-packages/graphitesend/graphitesend.py", line 291, in _send
    self.socket.sendall(message.encode("ascii"))
AttributeError: 'bytes' object has no attribute 'encode'

What's happening is that it's doing a double-encode: _dispatch_send() is calling message.encode('ascii'), producing a bytes object, and then _send() tries to encode to ASCII again. Which is allowed on Python 2 but fails with the above on Python 3 due to the latter's stricter unicode/bytes handling. Oh well...

@benhoyt

This comment has been minimized.

Show comment
Hide comment
@benhoyt

benhoyt Sep 6, 2016

@Linux-oiD FWIW, we ended up writing our own Python 3-ready library to solve this: https://github.com/Jetsetter/graphyte -- it works on Python 2.x and 3.x, and also doesn't use any additional 3rd party libraries (graphitesend requires "gevent" for async usage, graphyte just uses the Python standard "threading" module).

benhoyt commented Sep 6, 2016

@Linux-oiD FWIW, we ended up writing our own Python 3-ready library to solve this: https://github.com/Jetsetter/graphyte -- it works on Python 2.x and 3.x, and also doesn't use any additional 3rd party libraries (graphitesend requires "gevent" for async usage, graphyte just uses the Python standard "threading" module).

@Shir0kamii

This comment has been minimized.

Show comment
Hide comment
@Shir0kamii

Shir0kamii Dec 26, 2016

Collaborator

graphitesend is now Python3 ready and this problem should be fixed. Feel free to open a new issue if the problem persists.

Collaborator

Shir0kamii commented Dec 26, 2016

graphitesend is now Python3 ready and this problem should be fixed. Feel free to open a new issue if the problem persists.

@Shir0kamii Shir0kamii closed this Dec 26, 2016

@codelearnern

This comment has been minimized.

Show comment
Hide comment
@codelearnern

codelearnern Jul 30, 2018

Do pip install pygame in command line or terminal. If that doesn't work do python -m pip install pygame. If that doesn't work do py -m pip install pygame.

codelearnern commented Jul 30, 2018

Do pip install pygame in command line or terminal. If that doesn't work do python -m pip install pygame. If that doesn't work do py -m pip install pygame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment