jeudi 7 décembre 2017

Python, AttributeError: module 'sys' has no attribute 'modules'

I am having a superweird error (at least for me). If I open a ipython console and I try to import 'os' or 'sys', everything goes fine. I can access to 'sys.modules' without any problem. But when I run a series of tests over a codebase that I'm working on, I get the following error repeated when a library depending on 'os' module is imported (as, in this case, uuid, but it happens with more libs):

ERROR: test_wb_store_joins_transaction_on_use_after_abort (tests[...])
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/[personal folders]/tests/tester.py", line 103, in test_method_wrapper
    result = test_method()
  File "/[personal folders]/tests/zope/zbase.py", line 278, in test_wb_store_joins_transaction_on_use_after_abort
    store = self.zorm.get("name", "sqlite:")
  File "/[personal folders]/zorm/zope/zorm.py", line 176, in get
    return self.create(name, default_uri)
  File "/[personal folders]/zorm/zope/zorm.py", line 147, in create database =
  self._get_database(uri)
  File "/[personal folders]/zorm/zope/zorm.py", line 122, in _get_database
    return self._databases.setdefault(uri, create_database(uri))
  File "/[personal folders]/zorm/database.py", line 565, in create_database None, None, [""])
  File "/[personal folders]/zorm/databases/sqlite.py", line 34, in <module>
    from zorm.variables import Variable, BytesVariable
  File "/[personal folders]/zorm/variables.py", line 30, in <module>
    import uuid
  File "/[personal folders]/3.6/lib/python3.6/uuid.py", line 47, in <module>
    import os
  File "/[personal folders]/3.6/lib/python3.6/os.py", line 91, in <module>
AttributeError: module 'sys' has no attribute 'modules'

The line 91 in os.py is:

 sys.modules['os.path'] = path

I have tried from inside a virtualenv and from the general python installation, and both using Anaconda and the brew python version. I have tried to, for example, not import uuid in the entire codebase and then, when I test, the errors arise again but from another library (threading, for example)

I know that this is not a lot of information, but maybe somebody had in some occasion a similar problem, I don't know, maybe with importing several modules which in turn import the 'os' module several times it can fail accessing sys.modules?

Aucun commentaire:

Enregistrer un commentaire