Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError
#11
Hi Mark,
i would recommend to de-install 3.8 and install 3.4.4 with installer found here https://www.python.org/downloads/release/python-344/
Try your code and if it works, try updating to 3.4.4 to last version 3.4.10

An alternative way is to install Anaconda
and then you can create virtual environments with different versions of python.
Detailed tutorial here: https://docs.conda.io/projects/conda/en/...ments.html

(Nov-18-2019, 03:12 PM)baquerik Wrote: Strangely enough, that part of the code works good for me in Python 3.7.3 (Linux):

Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> stdout = sys.stdout.buffer
>>> type(stdout)
<class '_io.BufferedWriter'>
Using google search i also think this is a Unix vs Windows problem
so windows sys module has no sys.stdout.buffer attribute, unix version has.
Reply
#12
Sadly it wont work in 3.4 either.
So the main question is how to get this working under Windows.
Reply
#13
Try to get in contact with the maintainers of the package.
Reply
#14
Hi,

I did, but dont get a response...
Reply
#15
Maybe you can use the Windows Linux subsystem and run it in it.
Reply
#16
Hi,

Id like to have it working ok in Windows 10 Smile


Its so frustrating.
I can get time with device.gettime())
I can get program status with device.getprogstat())
I can get list files with device.list_files())

See below:

Device is connected: True
2019-11-19 21:35:42
Dict([('OSVer', b'CR1000.Std.32.04'), ('OSSig', 33907), ('SerialNbr', b'20810'), ('PowUpProg', b'CPU:basic - kopie.CR1'), ('CompState', 1), ('ProgName', b'CPU:basic - kopie.CR1'), ('ProgSig', 8023), ('CompTime', datetime.datetime(2019, 11, 18, 9, 15, 22)), ('CompResult', b'CPU:basic - kopie.CR1 -- Compiled in PipelineMode.\r\n')])
[b'CPU:', b'CPU:basic - kopie.CR1']
But the only issue is list the tables with data:

device.list_tables())
Reply
#17
Hi,

Unfortunately i dont get a response from the pycampbellcr1000 developer.
My only hope is someone over here can get it to work Smile

With kind regards.
Reply
#18
Hi,

I still havent managed to get it to work.
Someone able to help me a bit?
The code im running:
from pycampbellcr1000 import CR1000
import datetime
import os
import sys
import time
device = CR1000.from_url('Serial:COM3:38400')
 
print("Device is connected: %s" %device.connected)
print(device.gettime())
print(device.list_tables())
The actual error:
Traceback (most recent call last):
  File "C:\Users\Makada\Desktop\cr1000.py", line 1, in <module>
    from pycampbellcr1000 import CR1000
  File "C:\Python\lib\site-packages\pycampbellcr1000\__init__.py", line 13, in <module>
    from .logger import LOGGER, active_logger
  File "C:\Python\lib\site-packages\pycampbellcr1000\logger.py", line 14, in <module>
    from .compat import NullHandler
  File "C:\Python\lib\site-packages\pycampbellcr1000\compat.py", line 94, in <module>
    stdout = sys.stdout.buffer
AttributeError: 'StdOutputFile' object has no attribute 'buffer'
>>> 
The code which is named in the error, line 13 in _init_.py
# -*- coding: utf-8 -*-
'''
    PyCampbellCR1000
    ----------------

    The public API and command-line interface to PyCampbellCR1000.

    :copyright: Copyright 2012 Salem Harrache and contributors, see AUTHORS.
    :license: GNU GPL v3.

'''
# Make sure the logger is configured early:
from .logger import LOGGER, active_logger
from .pakbus import PakBus
from .device import CR1000


VERSION = '0.4dev'
__version__ = VERSION
The code which is named in the error, line 14 in logger.py
# -*- coding: utf-8 -*-
'''
    PyCampbellCR1000.logger
    -----------------------

    Logging setup.

    :copyright: Copyright 2012 Salem Harrache and contributors, see AUTHORS.
    :license: GNU GPL v3.

'''
from __future__ import unicode_literals
import logging
from .compat import NullHandler


LOGGER = logging.getLogger('pycampbellcr1000')
LOGGER.addHandler(NullHandler())


def active_logger():
    '''Initialize a speaking logger with stream handler (stderr).'''
    LOGGER = logging.getLogger('pycampbellcr1000')

    LOGGER.setLevel(logging.INFO)

    # Default to logging to stderr.
    formatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s ')
    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(formatter)

    LOGGER.addHandler(stream_handler)
The code which generates the error ( line 94 )is shown below.
With kind regards.


# coding: utf8
'''
    PyCampbellCR1000.compat
    -----------------------

    Workarounds for compatibility with Python 2 and 3 in the same code base.

    :copyright: Copyright 2012 Salem Harrache and contributors, see AUTHORS.
    :license: GNU GPL v3.

'''
import sys

# -------
# Pythons
# -------

# Syntax sugar.
_ver = sys.version_info

#: Python 2.x?
is_py2 = (_ver[0] == 2)

#: Python 3.x?
is_py3 = (_ver[0] == 3)

#: Python 3.0.x
is_py30 = (is_py3 and _ver[1] == 0)

#: Python 3.1.x
is_py31 = (is_py3 and _ver[1] == 1)

#: Python 3.2.x
is_py32 = (is_py3 and _ver[1] == 2)

#: Python 3.3.x
is_py33 = (is_py3 and _ver[1] == 3)

#: Python 3.4.x
is_py34 = (is_py3 and _ver[1] == 4)

#: Python 2.7.x
is_py27 = (is_py2 and _ver[1] == 7)

#: Python 2.6.x
is_py26 = (is_py2 and _ver[1] == 6)

# ---------
# Specifics
# ---------

if is_py2:
    if is_py26:
        from logging import Handler

        class NullHandler(Handler):
            def emit(self, record):
                pass
        from ordereddict import OrderedDict
    else:
        from logging import NullHandler
        from collections import OrderedDict
    from StringIO import StringIO

    ord = ord
    chr = chr

    def to_char(string):
        if len(string) == 0:
            return bytes('')
        return bytes(string[0])

    bytes = str
    str = unicode
    stdout = sys.stdout
    xrange = xrange


elif is_py3:
    from collections import OrderedDict
    from logging import NullHandler
    from io import StringIO

    ord = lambda x: x
    chr = lambda x: bytes([x])

    def to_char(string):
        if len(string) == 0:
            return str('')
        return str(string[0])

    str = str
    bytes = bytes
    stdout = sys.stdout.buffer
    xrange = range


def is_text(data):
    '''Check if data is text instance'''
    return isinstance(data, str)


def is_bytes(data):
    '''Check if data is bytes instance'''
    return isinstance(data, bytes)
Reply
#19
that is really weird
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout
<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
>>> sys.stdout.buffer
<_io.BufferedWriter name='<stdout>'>
>>>
works on both linux and windows
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#20
Hi buran,

Thanks for your reply.
I see you use other code, with ecoding among other text.

...unfortunately the developer of the package doesnt respond.
Its the py package "pycampbellcr1000"
https://pypi.org/project/PyCampbellCR1000/
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020