1

I have a cloud instance of a Linux machine (openSuSE) with multiple users. I have created a virtual environment and installed all my required libraries (including Klein).

I have two users "a" and "b". While logged in as "a" and inside virtualenv, when I open python shell at home directory and type

import klein

it imports normally.

Now when I change directory to

/home/b/

and run the same (open python shell, import klein) while being in the same virtualenv, it gives me an error.

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/a/.local/lib/python3.6/site-packages/klein/__init__.py", line 3, in <module>
    from klein._plating import Plating
  File "/home/a/.local/lib/python3.6/site-packages/klein/_plating.py", line 16, in <module>
    from .app import _call
  File "/home/a/.local/lib/python3.6/site-packages/klein/app.py", line 19, in <module>
    from twisted.internet import endpoints, reactor
  File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/endpoints.py", line 58, in <module>
    from twisted.protocols.tls import TLSMemoryBIOFactory
  File "/home/a/.local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 63, in <module>
    from twisted.internet._sslverify import _setAcceptableProtocols
  File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 158, in <module>
    verifyHostname, VerificationError = _selectVerifyImplementation()
  File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 141, in _selectVerifyImplementation
    from service_identity import VerificationError
  File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/__init__.py", line 7, in <module>
    from . import cryptography, pyopenssl
  File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/cryptography.py", line 16, in <module>
    from .exceptions import SubjectAltNameWarning
  File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/exceptions.py", line 21, in <module>
    @attr.s
AttributeError: module 'attr' has no attribute 's'

Command "which python" gives same address at both location which is my virtualenv python address and that should be expected.

But what causes this weird python shell behavior.

Thank you

2 Answers2

2

I solved it and a very shameful reason caused the error.

One of the modules Twisted uses is "attr" module. I had named one of my files attr.py and that is what was causing all the error.

I myself am not deleting this question if moderation has no problem, maybe somebody like me might be stuck at the same situation. It may help them.

Never name your python files same as that of any standard module unless overriding.

Also if your issue persists, then Jean's answer will definitely resolve it.

1

There can be multiple different Python packages that provide the same Python module. For example, there are at least two packages that provide the attr module:

https://pypi.org/project/attr/
https://pypi.org/project/attrs/

It's possible you've installed the wrong package based on the requirements. You can check what you have installed with pip freeze.

Jean-Paul Calderone
  • 47,755
  • 6
  • 94
  • 122