Background
I have installed python 3.10.11 on my Windows 10 machine using installer ‘python-3.10.11-amd64.exe’. But whenever I try to run any ‘pip’ command it shows error now.
Error comes as below
C:WINDOWSsystem32>pip -version
Traceback (most recent call last):
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310librunpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310Scriptspip.exe__main__.py", line 4, in <module>
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310libsite-packagespip_internalclimain.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310libsite-packagespip_internalcliautocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310libsite-packagespip_internalclimain_parser.py", line 9, in <module>
from pip._internal.build_env import get_runnable_pip
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310libsite-packagespip_internalbuild_env.py", line 15, in <module>
from pip._vendor.packaging.requirements import Requirement
File "C:Usersinnabal1AppDataLocalProgramsPythonPython310libsite-packagespip_vendorpackaging__init__.py", line 5, in <module>
from .__about__ import (
ValueError: source code string cannot contain null bytes
I am unable to rectify this error.
Python version command shows as below
C:WINDOWSsystem32>python --version
Python 3.10.11
What I tried
I tried uninstalling and re-installing Python but it did not help.
Note
I earlier had Python 3.8.*. I have both VS Code and Pycharm installed in the same machine
2
Answers
That means there’s a null byte in the
pip_vendorpackaging__init__.py
module.Chances are that file has been corrupted by e.g. filesystem corruption, bit flip, bad luck, etc.
I’d suggest
C:Usersinnabal1AppDataLocalProgramsPythonPython310
out (you can rename it to e.g.Python310-old
, or just deleting it)are you sure you 100% uninstalled python? because according to the error, it seems you had a null bytes (