OSError: [Errno 9] 在 python 中使用 pip 指令時出現錯誤的檔案描述符

OSError: [Errno 9] 在 python 中使用 pip 指令時出現錯誤的檔案描述符

當我嘗試在 cmd 中使用 pip 升級 pip 或安裝新軟體包時,顯示以下錯誤。我已經卸載並重新安裝了python,但問題仍然存在。我目前的python版本是3.7.3,我在Windows 10平台上運行它。此錯誤訊息顯示:

OSError: [Errno 9] 錯誤的檔案描述符

如何解決這個問題?以及導致此錯誤的原因。

錯誤訊息是:

C:\Users\ELCOT>python -m pip install -upgrade pip
Traceback (most recent call last):
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\ELCOT\AppData\Local\Programs\Python\Python37-32\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\main_parser.py", line 12, in <module>
    from pip._internal.commands import (
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\base_command.py", line 20, in <module>
    from pip._internal.download import PipSession
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 15, in <module>
    from pip._vendor import requests, six, urllib3
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\__init__.py", line 114, in <module>
    from . import utils
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\utils.py", line 26, in <module>
    from ._internal_utils import to_native_string
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\compat.py", line 64, in <module>
    from http.cookies import Morsel
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 859, in get_code
  File "<frozen importlib._bootstrap_external>", line 917, in get_data
  OSError: [Errno 9] Bad file descriptor

C:\Users\ELCOT>pip install numpy
Traceback (most recent call last):
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\ELCOT\AppData\Local\Programs\Python\Python37-32\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\main_parser.py", line 12, in <module>
    from pip._internal.commands import (
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\commands\completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\cli\base_command.py", line 20, in <module>
    from pip._internal.download import PipSession
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_internal\download.py", line 15, in <module>
    from pip._vendor import requests, six, urllib3
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\__init__.py", line 114, in <module>
    from . import utils
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\utils.py", line 26, in <module>
    from ._internal_utils import to_native_string
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\_internal_utils.py", line 11, in <module>
    from .compat import is_py2, builtin_str, str
  File "c:\users\elcot\appdata\local\programs\python\python37-32\lib\site-packages\pip\_vendor\requests\compat.py", line 64, in <module>
    from http.cookies import Morsel
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 859, in get_code
  File "<frozen importlib._bootstrap_external>", line 917, in get_data
  OSError: [Errno 9] Bad file descriptor

答案1

我想最近(最近3年左右)Windows更新了一些安全性設置,可能是為了對抗勒索軟體,所以我們編寫的程序,例如python程序,只能讀/寫C:\Users\xxxxx\Documents內的文件文件夾。

我曾經創建一個特殊的工作資料夾作為 C:\working 並完成所有編碼工作以獲取樂趣,現在由於此安全更新,該程式不再工作。將完全相同的程式移到 C:\Users\xxxxx\Documents 中,然後它就可以像往常一樣運作了。

相關內容