blinker does not work in Python 2.6 - python

import blinker
from blinker import signal
class Ticket():
#classmethod
def update(cls):
pass
ticket_created = signal('CREATED')
ticket_created.connect(Ticket.update)
This snippet of code works well on Python 2.7. But does not work on Python 2.6. I get this trace:
Traceback (most recent call last):
File "btest.py", line 10, in <module>
ticket_created.connect(Ticket.update)
File "/home/gavika/env2/lib/python2.6/site-packages/blinker/base.py", line 113, in connect
receiver_ref = reference(receiver, self._cleanup_receiver)
File "/home/gavika/env2/lib/python2.6/site-packages/blinker/_utilities.py", line 134, in reference
weak = callable_reference(object, callback)
File "/home/gavika/env2/lib/python2.6/site-packages/blinker/_utilities.py", line 145, in callable_reference
return BoundMethodWeakref(target=object, on_delete=callback)
File "/home/gavika/env2/lib/python2.6/site-packages/blinker/_saferef.py", line 143, in __new__
base.__init__(target, on_delete, *arguments, **named)
File "/home/gavika/env2/lib/python2.6/site-packages/blinker/_saferef.py", line 185, in __init__
self.weak_self = weakref.ref(im_self, remove)
TypeError: cannot create weak reference to 'classobj' object
Is there a way I could get this to work in 2.6 environment?

Yes, new-style classes is the answer.
class Ticket(object):
...
Solves the issue.

Related

Chatterbot installation working, but broken calls to variables

I installed chatterbot in my terminal earlier today using virtual studio code's terminal. I saw that both chatterbot and chatterbot_corpus worked in installation. Then, I made the following python document:
EDIT: Turns out I should define a chatbot variable first.
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer
conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]
bot = ChatBot('Maya')
trainer = ListTrainer(bot)
trainer.train(conversation)
This was my code
it says this however
bot = ChatBot('Maya')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 22, in __init__
from sqlalchemy import create_engine
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\__init__.py", line 8, in <module>
from . import util as _util # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
from ._collections import coerce_generator_arg # noqa
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
from .compat import binary_types
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
Does anyone know how to fix this easily?
EDIT: I just updated python using pip install --upgrade ipython in terminal, but it didn't fix the issue
EDIT 2: Well now I tried updating a package using pip install sqlalchemy --upgrade
But now it gives
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>,
got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
I am in the latest version though
PS C:\Users\Subha> Python --version
Python 3.9.6
EDIT 3: Now it comes up with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\chatterbot.py", line 34, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\utils.py", line 54, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\chatterbot\storage\sql_storage.py", line 46, in __init__
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\dialects\sqlite\base.py", line 2009, in has_table
self._ensure_has_table_connection(connection)
File "C:\Users\Subha\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\sqlalchemy\engine\default.py", line 341, in _ensure_has_table_connection
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The argument passed to Dialect.has_table() should be a <class 'sqlalchemy.engine.base.Connection'>, got <class 'sqlalchemy.engine.base.Engine'>. Additionally, the Dialect.has_table() method is for internal dialect use only; please use ``inspect(some_engine).has_table(<tablename>>)`` for public API use.
it seems the python upgrade worked with regard to the initial error on time.clock. This new error you are seeing is quite different to the previous one. In this case you need to go into chatterbot/storage/sql_storage.py and comment out if not self.engine.dialect.has_table(self.engine, 'Statement'): and leave only self.create_database(). This means that instead of checking whether a database table has been created which is triggering the error, it will just create the DB every time, which i expect to work fine.
# if not self.engine.dialect.has_table(self.engine, 'Statement'):
self.create_database()

error trying to use marshmallow_dataclass

I am trying to use marshmallow_dataclass in a python (3.9) test in pycharm to try it (marshmallow_dataclass) out and get an error.
Not sure what I am doing wrong. I have installed marshmallow_dataclass (8.1.0)
I have so far been successful in using marshmallow (3.8.0) and marshmallow_oneofschema (2.1.0) so far
(new to python but not programming)
Code is:
import marshmallow_dataclass
import unittest
class Tests(unittest.TestCase):
def test_serialize(self):
print("Hello")
Error is:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2020.2.3\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py", line 35, in <module>
sys.exit(main(argv=args, module=None, testRunner=unittestpy.TeamcityTestRunner, buffer=not JB_DISABLE_BUFFERING))
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\main.py", line 100, in __init__
self.parseArgs(argv)
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\main.py", line 147, in parseArgs
self.createTests()
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\main.py", line 158, in createTests
self.test = self.testLoader.loadTestsFromNames(self.testNames,
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\loader.py", line 220, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\loader.py", line 220, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\unittest\loader.py", line 154, in loadTestsFromName
module = __import__(module_name)
File "C:\xxxx\dev\repos\python\solar\pvoutput-publisher\test\test_serialization\test_delme.py", line 1, in <module>
import marshmallow_dataclass
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\marshmallow_dataclass\__init__.py", line 59, in <module>
import typing_inspect
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\typing_inspect.py", line 25, in <module>
from typing_extensions import Literal
File "C:\xxxx\AppData\Local\Programs\Python\Python39\lib\site-packages\typing_extensions.py", line 2084, in <module>
def TypeAlias(self, parameters):
TypeError: __init__() missing 1 required positional argument: 'doc'```
I hit similar error on python 3.9 alpha release (3.9.0a5), I am not sure the version of typing_extensions.py in your environment (maybe it is v3.7.4.3 ?).
The root cause is that :
the function TypeAlias() is decorated directly with the class _TypeAliasForm, which is subclass of typing._SpecialForm in python stardard library
typing._SpecialForm.__init__() in your python environment has extra argument doc , since the class _TypeAliasForm is a decorator for TypeAlias(), Python couldn't provide extra argument doc when instantiating _TypeAliasForm on decorating process.
In short, your typing_extensions.py is out of sync with your python interpreter, see the source code for detail:
TypeAlias() and _TypeAliasForm class .
typing._SpecialForm.__init__() in python 3.9.0a5
typing._SpecialForm.__init__() in python 3.9.0a6
It seems that the issue happens from python 3.9.0a1 to 3.9.0a5, so the solutions are :
upgrade your python to final release version
if you are not allowed to upgrade python for some other reasons, maybe you can monkey-patch typing._SpecialForm , here is the example for monkey-patching :
from typing import _SpecialForm
origin_getitem = _SpecialForm.__getitem__
def patch_init(self, name, doc=None):
if doc is None and callable(name):
if hasattr(name, '__doc__'):
doc = name.__doc__
self._name = name
self._doc = doc
def patch_getitem(self, parameters):
item = None
if callable(self._name):
item = self._name(self=self, parameters=parameters)
else:
item = origin_getitem(self=self, parameters=parameters)
return item
if not hasattr(_SpecialForm.__init__, 'patched'):
_SpecialForm.__init__ = patch_init
setattr(_SpecialForm.__init__, 'patched', True)
if not hasattr(_SpecialForm.__getitem__, 'patched'):
_SpecialForm.__getitem__ = patch_getitem
setattr(_SpecialForm.__getitem__, 'patched', True)

assert group is none

I am trying to run a preprocessing pipeline using nipype and I get the following error message:
Traceback (most recent call last):
File "preprocscript.py", line 211, in <module>
preproc.run('MultiProc', plugin_args={'n_procs': 8})
File "/sw/anaconda/3/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py", line 579, in run
runner = plugin_mod(plugin_args=plugin_args)
File "/sw/anaconda/3/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 162, in __init__
initargs=(self._cwd,)
File "/sw/anaconda/3/lib/python3.6/multiprocessing/pool.py", line 175, in __init__
self._repopulate_pool()
File "/sw/anaconda/3/lib/python3.6/multiprocessing/pool.py", line 236, in _repopulate_pool
self._wrap_exception)
File "/sw/anaconda/3/lib/python3.6/multiprocessing/pool.py", line 250, in _repopulate_pool_static
wrap_exception)
File "/sw/anaconda/3/lib/python3.6/multiprocessing/process.py", line 73, in __init__
assert group is None, 'group argument must be None for now'
AssertionError: group argument must be None for now
and I am not sure what exactly might be wrong in my code that leads to this or if this is an issue with my software.
I am on a linux system and use python 3.6.
The module you are using has a ProcessPoolExecuter being used in it. In Python 3.7 they added some additional arguments to that class, namely initargs which is what is being called in nipype multiprocess module you are using. Unfortunately it is not backwards compatible to 3.6 and they did not write in another way to use that module.
Your options are to upgrade or not use the multiprocessing portion of nipype.

use antlr4 python runtime with python 2.6

Is it possible to use the antlr4 python runtime with python 2.6 or is the minimun required version python 2.7? I want to use it on CentOS 6.3 that comes with python 2.6.6. If it is not possible, is it known what features of python 2.7 that is used?
Finally I can answer this myself. It is not possible to use antlr4-python2 runtime on centos6.3 (that has python 2.6.6), I have installed it and tried this example. The result is as follows:
[lg#localhost py]$ python test.py data.txt
Traceback (most recent call last):
File "test.py", line 15, in <module>
main(sys.argv)
File "test.py", line 10, in main
tree = parser.r()
File "/home/lg/antlr/py/HelloParser.py", line 74, in r
self.enterRule(localctx, 0, self.RULE_r)
File "/usr/lib/python2.6/site-packages/antlr4/Parser.py", line 367, in enterRule
self._ctx.start = self._input.LT(1)
File "/usr/lib/python2.6/site-packages/antlr4/CommonTokenStream.py", line 85, in LT
self.lazyInit()
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 209, in lazyInit
self.setup()
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 212, in setup
self.sync(0)
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 134, in sync
fetched = self.fetch(n)
File "/usr/lib/python2.6/site-packages/antlr4/BufferedTokenStream.py", line 146, in fetch
t = self.tokenSource.nextToken()
File "/usr/lib/python2.6/site-packages/antlr4/Lexer.py", line 131, in nextToken
tokenStartMarker = self._input.mark()
AttributeError: 'builtin_function_or_method' object has no attribute 'mark'
[lg#localhost py]$
The example you used was badly written. input is the name of a built-in Python function. Give the Lexer a FileStream and it might work.

How to use Atk.Relation in Python

i am trying to migrate an application from gtk2 to gtk3 using GObject Introspection (gi.repository).
The problem i have now is creating an Atk.Relation in an accessibility method that looks like this:
from gi.repository import Atk
def atk_acc(obj, lbl):
atk_obj = obj.get_accessible()
atk_l = lbl.get_accessible()
relation_set = atk_l.ref_relation_set()
relation = Atk.Relation.new([atk_obj], 1, Atk.RelationType.LABEL_FOR)
relation_set.add(relation)
When i run the application, it breaks with an exception:
Traceback (most recent call last):
File "/home/erick/Desarrollo/git/canaima-instalador/canaimainstalador/main.py", line 237, in siguiente
CFG['w'].next('Metodo', Metodo, (CFG), PasoMetodo(CFG))
File "/home/erick/Desarrollo/git/canaima-instalador/canaimainstalador/pasos/metodo.py", line 63, in __init__
atk_acc(self.cmb_discos, self.lbl1)
File "/home/erick/Desarrollo/git/canaima-instalador/canaimainstalador/mod_accesible.py", line 37, in atk_acc
relation = Atk.Relation.new([atk_obj], 1, Atk.RelationType.LABEL_FOR)
File "/usr/lib/python2.7/dist-packages/gi/types.py", line 72, in constructor
return info.invoke(cls, *args, **kwargs)
TypeError: Expected Atk.Object, but got GObjectMeta
In ATK documentation says that the first argument of Atk.Relation.new is an array.
What i'm doing wrong here?

Categories

Resources