Getting error Bad File Descriptor while installing pip

1.5k Views Asked by At

whenever i try to install pip i always get this error. pls help . i dont know how to fix this i tried doing it using the default python executable using the modify method and also tried the get-pip.py file method nothing works. i have checked my path variables too so the scripts folder is there but pip is not installed.

    PS C:\Users\ismai\Desktop\programs\PYTHON> python get-pip.py
Traceback (most recent call last):
  File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 23704, in <module>
    main()
  File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 198, in main
    bootstrap(tmpdir=tmpdir)
  File "C:\Users\ismai\Desktop\programs\PYTHON\get-pip.py", line 83, in bootstrap
    from pip._internal.commands.install import InstallCommand
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\commands\install.py", line 17, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\cli\req_command.py", line 16, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_internal\index\collector.py", line 14, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\__init__.py", line 125, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\utils.py", line 27, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\_internal_utils.py", line 11, in <module>
  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 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "C:\Users\ismai\AppData\Local\Temp\tmpz82tcza4\pip.zip\pip\_vendor\requests\compat.py", line 65, in <module>
  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 786, in exec_module
  File "<frozen importlib._bootstrap_external>", line 922, in get_code
  File "<frozen importlib._bootstrap_external>", line 980, in get_data
OSError: [Errno 9] Bad file descriptor
8

There are 8 best solutions below

0
mysteri0us On BEST ANSWER

Ok guys i tried unistalling this new version(3.9) and then installed an old version(3.7) and then ran the command python get-pip.py and magically it worked. if anyone in future wants to fix this issue then try this. i also read the python documenttion and apparantly they have a command if pip isnt installed on your version of python that is python -m ensurepip so you can try that too.

3
BeeFriedman On

Uninstall python and then download it from https://www.python.org/downloads/ reinstall it and make sure to check the box that adds pip to PATH.

0
Youssif Sayd On

I actually had a similar problem and tried every possible solution, the only one which worked with me is to uninstall python and reinstall it in different partition other than the C , it will work !

0
adps On

Go to the folder in which you Python installer is there and click on it. It will open the installer and show "modify setup":

Screenshot of Python install wizard on top of PyCharm

1
adps On

And then click on "Uninstall". After uninstall done click on close and again go to your installer and click on it and after that it will show like this.

1
adps On

After check Add python to PATH and click on "customize installation". Check everything in advanced option and click install.

Done!

0
quantumboy On

In a python virtual environment, venv, I was using pip freeze to save requirements when I got an "OSError: [Errno 9] Bad file descriptor". It turned out the my Norton antivirus protection found pip to be suspicious and was blocking it. After excluding pip.exe in Norton, that is letting Norton know it was not a threat, the problem was solved.

0
Ed Nutting On

4 years later and this issue arises for a different reason. Leaving this answer here to help others.

If you encounter "Bad File Descriptor" when using Python, Pip or Poetry on Windows:

It is possible that Windows Security is blocking access to your files. It may do this as part of Controlled Folder Access, as part of Virus & Threat Protection. If this is the cause of the problem, the solution is to allow Python to access your documents. (The solution is not to turn off virus and threat protection. You can solve this without having to give up on anti-virus.)

Steps:

  1. Open Windows Security
  2. Go to Virus & Threat Protection
  3. Go to Virus & Threat Protection Settings (by clicking Manage Settings)
  4. Scroll down to find Controlled Folder Access
  5. Click Manage Controlled folder access
  6. Is is turned on? If no, stop here as this can't be the cause of the issue. If yes, proceed.
  7. Open the Block History
  8. Inspect the list of blocked folder accesses. Do you see a recent entry for python.exe trying to access the folder you were working in? If no, stop here as controlled folder access is not the cause of the issue. If yes, proceed.
  9. Go back to Manage Controlled folder access
  10. Click "Allow an app through Controlled folder access"
  11. Click "Add an allowed app"
  12. Click "Recently blocked apps"
  13. You should see Python in the list. Click on it and allow it through. (If not, click "Add an allowed app" then use "Browse all apps" to manually find python.exe -- from a command prompt (not powershell), use where python.exe to discover Python's location.)
  14. You're done. Retry using python/pip/poetry.

Good luck!


Footnote:

This is not the only possible cause of Bad File Descriptor. The above steps tell you to stop if you don't find the logs which tell you if Controlled Folder Access is the cause of your problem. Please don't add Python to your exclusion list if it's not the cause of your problem as that just risks opening you up to viruses in the future.