Skip to content
Advertisement

Module Six has no attribute ensure_text

Out of the blue, my python installation seems to have broken. When trying to run a python script, I get the following…

[michael@arch ~/Code/CTF/aero/house]$ ./solve.py 
Traceback (most recent call last):
  File "/home/michael/Code/CTF/aero/house/./solve.py", line 5, in <module>
    from pwn import *
  File "/home/michael/.local/lib/python3.9/site-packages/pwn/__init__.py", line 20, in <module>
    pwnlib.update.check_automatically()
  File "/home/michael/.local/lib/python3.9/site-packages/pwnlib/update.py", line 199, in check_automatically
    log.info("n".join(message))
  File "/home/michael/.local/lib/python3.9/site-packages/pwnlib/log.py", line 395, in info
    self._log(logging.INFO, message, args, kwargs, 'info')
  File "/home/michael/.local/lib/python3.9/site-packages/pwnlib/log.py", line 292, in _log
    msg = six.ensure_text(msg)
AttributeError: module 'six' has no attribute 'ensure_text'

Trying to reinstall the module using pip also breaks…

[michael@arch ~/Code/CTF/aero/house]$ python3 -m pip install pwntools
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.9/site-packages/pip/__main__.py", line 26, in <module>
    sys.exit(_main())
  File "/usr/lib/python3.9/site-packages/pip/_internal/cli/main.py", line 73, in main
    command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
  File "/usr/lib/python3.9/site-packages/pip/_internal/commands/__init__.py", line 105, in create_command
    module = importlib.import_module(module_path)
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 14, in <module>
    from pip._internal.cache import WheelCache
  File "/usr/lib/python3.9/site-packages/pip/_internal/cache.py", line 15, in <module>
    from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
  File "/usr/lib/python3.9/site-packages/pip/_internal/utils/temp_dir.py", line 11, in <module>
    from pip._vendor.six import ensure_text
ImportError: cannot import name 'ensure_text' from 'six' (/home/michael/.local/lib/python3.9/site-packages/six.py)

I have read that this is caused by running pip as root, but I have not done this. I also haven’t made any recent upgrades or installed any new packages. So far I have tried setting PYTHONPATH, reinstalling python, and reinstalling pip, and none of these options have worked. Does anyone have any ideas? Thanks in advance!

EDIT: I also tried updating python and pip, which didn’t work.

Requested Information:

>>> import six; print(six.__file__)
/home/michael/.local/lib/python3.9/site-packages/six.py
>>> print(six.__version__)
1.10.0

Advertisement

Answer

I was able to update six by doing a wget https://raw.githubusercontent.com/benjaminp/six/master/six.py in ~/.local/lib/python3.9/site-packages. This solved the problem.

Advertisement