ImportError: cannot import name 'ensure_str' from 'six' - python

when i tried to install netfilterqueue this error came up.
even i can't uninstall/check/install using pip.
And i searched over the stackoverflow and one of those said use :
sudo pip install -U setuptools
And again this error came up.
Traceback (most recent call last):
File "/usr/bin/pip", line 33, in <module>
sys.exit(load_entry_point('pip==20.1.1', 'console_scripts', 'pip')())
File "/usr/lib/python3.8/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.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 15, in <module>
from pip._internal.distributions import (
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/__init__.py", line 2, in <module>
from pip._internal.distributions.wheel import WheelDistribution
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/wheel.py", line 5, in <module>
from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/usr/lib/python3.8/site-packages/six.py)
Thanks in advance.

I was able to make this work by copying six.py from https://github.com/benjaminp/six.git into /usr/lib/python3.8/six.py ... you'll need sudo to create or update this file.

Related

Installing html5lib for Python on Ubunto

Dependencies on html5lib are pretty broad across developer tools on Linux. I uncovered this issue while attempting to implement the selenium test suite for my Django app. When I attempt to pip install, I receive the below error. How do I adjust my system to grab and install html5lib?
Traceback (most recent call last):
File "/home/satch/.local/bin/pip", line 8, in <module>
sys.exit(main())
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 104,
in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24,
in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 16,
in <module>
from pip._internal.index.package_finder import PackageFinder
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 21,
in <module>
from pip._internal.index.collector import parse_links
File "/usr/lib/python3/dist-packages/pip/_internal/index/collector.py", line 14,
in <module>
from pip._vendor import html5lib, requests
ImportError: cannot import name 'html5lib' from 'pip._vendor'
(/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)

python3 pip upgrade NameError: name 'unicode' is not defined

If I want to install a package with pip3 I receive following output:
Traceback (most recent call last):
File "/opt/habapp/bin/pip3", line 8, in <module>
sys.exit(main())
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.req.constructors import (
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/req/__init__.py", line 11, in <module>
from .req_file import parse_requirements
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/req/req_file.py", line 25, in <module>
from pip._internal.req.constructors import (
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 28, in <module>
from pip._internal.req.req_install import InstallRequirement
File "/opt/habapp/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 17, in <module>
from pip._vendor.pep517.wrappers import Pep517HookCaller
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 14, in <module>
File "/usr/lib/python3.8/importlib/resources.py", line 11, in <module>
from typing import Iterable, Iterator, Optional, Set, Union # noqa: F401
File "/home/openhabvm/.local/lib/python2.7/site-packages/typing.py", line 782, in <module>
AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined
(habapp) openhabvm#OpenHABVM:/opt/habapp$ ^C
(habapp) openhabvm#OpenHABVM:/opt/habapp$ deactivate
openhabvm#OpenHABVM:/opt/habapp$ python3 -m pip install --upgrade pip
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
sys.exit(_main())
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3/dist-packages/pip/_internal/req/__init__.py", line 11, in <module>
from .req_file import parse_requirements
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_file.py", line 25, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3/dist-packages/pip/_internal/req/constructors.py", line 28, in <module>
from pip._internal.req.req_install import InstallRequirement
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 17, in <module>
from pip._vendor.pep517.wrappers import Pep517HookCaller
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 14, in <module>
File "/usr/lib/python3.8/importlib/resources.py", line 11, in <module>
from typing import Iterable, Iterator, Optional, Set, Union # noqa: F401
File "/home/openhabvm/.local/lib/python2.7/site-packages/typing.py", line 782, in <module>
AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 32, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 26, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 26, in <module>
from apt.package import Package as Package, Version as Version
File "/usr/lib/python3/dist-packages/apt/package.py", line 42, in <module>
from typing import (Any, Iterable, Iterator, List, Optional, Set,
File "/home/openhabvm/.local/lib/python2.7/site-packages/typing.py", line 782, in <module>
AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined
Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
sys.exit(_main())
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3/dist-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 21, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3/dist-packages/pip/_internal/req/__init__.py", line 11, in <module>
from .req_file import parse_requirements
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_file.py", line 25, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3/dist-packages/pip/_internal/req/constructors.py", line 28, in <module>
from pip._internal.req.req_install import InstallRequirement
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 17, in <module>
from pip._vendor.pep517.wrappers import Pep517HookCaller
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl/pep517/wrappers.py", line 14, in <module>
File "/usr/lib/python3.8/importlib/resources.py", line 11, in <module>
from typing import Iterable, Iterator, Optional, Set, Union # noqa: F401
File "/home/openhabvm/.local/lib/python2.7/site-packages/typing.py", line 782, in <module>
AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined
This also occurs if I want to upgrade pip:
python3 -m pip install --upgrade pip
I upgraded Ubuntu 16.04 to 20.04. I am sure that I have deleted Python 2.
sudo update-alternatives --config python3
update-alternatives: error: no alternatives for python3
And i used sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 without errors
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
I hope you can help me. Thanks in advance.

How solve this Import error when pip list at venv?

I am using python3.8.8 in windows10. I just typed pip list in
venv(CMD) which showed a big error. I was using this venv for pip
installing tensorflow which also showed this similar error
## Heading ## (venv) C:\Users\HP>pip list Traceback (most recent
call last): File
"c:\users\hp\appdata\local\programs\python\python38\lib\runpy.py",
line 194, in _run_module_as_main
return _run_code(code, main_globals, None, File "c:\users\hp\appdata\local\programs\python\python38\lib\runpy.py",
line 87, in _run_code
exec(code, run_globals) File "C:\Users\HP\venv\Scripts\pip.exe\__main__.py", line 7, in <module>
File "c:\users\hp\venv\lib\site-packages\pip\_internal\cli\main.py",
line 71, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args)) File
"c:\users\hp\venv\lib\site-packages\pip\_internal\commands\__init__.py",
line 96, in create_command
module = importlib.import_module(module_path) File "c:\users\hp\appdata\local\programs\python\python38\lib\importlib\__init__.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen
importlib._bootstrap_external>", line 783, in exec_module File
"<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed File "c:\users\hp\venv\lib\site-packages\pip\_internal\commands\list.py",
line 5, in <module>
from pip._internal.cli.req_command import IndexGroupCommand File
"c:\users\hp\venv\lib\site-packages\pip\_internal\cli\req_command.py",
line 16, in <module>
from pip._internal.index.collector import LinkCollector File "c:\users\hp\venv\lib\site-packages\pip\_internal\index\collector.py",
line 16, in <module>
from pip._vendor import html5lib, requests File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\__init__.py",
line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\html5parser.py",
line 6, in <module>
from . import _inputstream File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\_inputstream.py",
line 10, in <module>
from pip._vendor import webencodings ImportError: cannot import name 'webencodings' from 'pip._vendor'
(c:\users\hp\venv\lib\site-packages\pip\_vendor\__init__.py)

Pip source code string can't contain null bytes

I'm trying to list pip packages, but when I run pip list, I get this error message
Traceback (most recent call last):
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe\__main__.py", line 7, in <module>
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\list.py", line 9, in <module>
from pip._internal.cli.req_command import IndexGroupCommand
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\req_command.py", line 16, in <module>
from pip._internal.index.collector import LinkCollector
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\collector.py", line 14, in <module>
from pip._vendor import html5lib, requests
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\__init__.py", line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\html5parser.py", line 6, in <module>
from . import _inputstream
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\_inputstream.py", line 10, in <module>
from pip._vendor import webencodings
ValueError: source code string cannot contain null bytes
I thought it was just a problem with the list command and forgot about it, so I installed a pip package. However, when I put the command in, I still got the same error message. Pip was working fine before so I don't know if there's a problem with a piece of code I need to fix or something.

ImportError: cannot import name 'ensure_str' from 'six' (/usr/lib/python3.8/site-packages/six.py)

I am receiving this error on multiple commands, similar to the problem explained in this question. But I am not even able to run it in sudo, non-sudo(if thats a thing) and also root account(I specifically logged into the root account to run this, but failed)
Here is the error I am thrown every time.
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/usr/lib/python3.8/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.8/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/freeze.py", line 12, in <module>
from pip._internal.operations.freeze import freeze
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/freeze.py", line 17, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3.8/site-packages/pip/_internal/req/__init__.py", line 11, in <module>
from .req_file import parse_requirements
File "/usr/lib/python3.8/site-packages/pip/_internal/req/req_file.py", line 25, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 28, in <module>
from pip._internal.req.req_install import InstallRequirement
File "/usr/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 30, in <module>
from pip._internal.operations.install.wheel import install_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/install/wheel.py", line 33, in <module>
from pip._internal.utils.wheel import parse_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/usr/lib/python3.8/site-packages/six.py)
Note : I was initially trying to install tensorflow, then other commands like pip freeze and pip uninstall some-package also threw this error.
I have already tried reinstalling pip without any errors. I am on Manjaro, so i ran
pacman -Rcn python-pip
and then
pacman -S python-pip
$ pacman -S extra/python-six did the trick!

Categories