skip to Main Content

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


  1. ValueError: source code string cannot contain null bytes

    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

    1. uninstalling Python
    2. cleaning C:Usersinnabal1AppDataLocalProgramsPythonPython310 out (you can rename it to e.g. Python310-old, or just deleting it)
    3. reinstalling Python so you get a clean copy.
    Login or Signup to reply.
  2. are you sure you 100% uninstalled python? because according to the error, it seems you had a null bytes () somewhere inside your inner python python library. try uninstalling python completely and then check if you have any python fails remaining. if you do, delete them. after that, install python and check if it works

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search