PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: after installing python-certifi-win32
Asked Answered
N

3

14

I installed python-certifi-win32 package and after that, I am getting below error, when I import anything or pip install anything, the fail with the final error of PermissionError.

I tried rebooting the box. It didn't work. I am unable to uninstall the package as pip is erroring out too.

I am unable to figure out the exact reason why this error is happening. It doesn't seem to be code specific, seems related to the library I installed

PS C:\Users\visha\PycharmProjects\master_test_runner> pip install python-certifi-win32                                                                
Traceback (most recent call last):
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 89, in _tempfile
    os.write(fd, reader())
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\importlib\abc.py", line 371, in read_bytes
    with self.open('rb') as strm:
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\importlib\_adapters.py", line 54, in open
    raise ValueError()
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\Scripts\pip.exe\__main__.py", line 4, in <module>
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
    from pip._internal.cli import cmdoptions
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 23, in <module>
    from pip._internal.cli.parser import ConfigOptionParser
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\cli\parser.py", line 12, in <module>
    from pip._internal.configuration import Configuration, ConfigurationError
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\configuration.py", line 21, in <module>
    from pip._internal.exceptions import (
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_internal\exceptions.py", line 8, in <module>
    from pip._vendor.requests.models import Request, Response
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_vendor\requests\__init__.py", line 123, in <module>
    from . import utils
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\pip\_vendor\requests\utils.py", line 25, in <module>
    from . import certs
  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 "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\importer.py", line 170, in exec_module
    notify_module_loaded(module)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
    return wrapped(*args, **kwargs)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
    hook(module)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\certifi_win32\wrapt_pip.py", line 35, in apply_patches
    import certifi
  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 "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\importer.py", line 170, in exec_module
    notify_module_loaded(module)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
    return wrapped(*args, **kwargs)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
    hook(module)
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
    certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
  File "C:\Users\visha\PycharmProjects\GUI_Automation\venv\lib\site-packages\certifi\core.py", line 37, in where
    _CACERT_PATH = str(_CACERT_CTX.__enter__())
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "C:\Users\visha\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 95, in _tempfile
    os.remove(raw_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\visha\\AppData\\Local\\Temp\\tmpy_tb8siv'
PS C:\Users\visha\PycharmProjects\master_test_runner> 
Nephelinite answered 26/4, 2022 at 9:11 Comment(1)
Does this answer your question? pip broke after downlading python-certifi-win32Hannah
N
31

I ran into the same issue today. I corrected it by removing two *.pth files that were created when I had installed python-certifi-win32. This prevents python-certifi-win32 from loading when python is run.

The files are listed below, and were located here:

C:\Users\<username>\AppData\Local\Programs\Python\Python310\Lib\site-packages

Files:

python-certifi-win32-init.pth
distutils-precedence.pth

Removing these files allowed me to install/uninstall other modules.

Noe answered 2/5, 2022 at 12:59 Comment(5)
Thanks that helped me remove the package via pipNephelinite
This worked, but why does it work?Fiesta
If you are using an Anaconda environment, this would be located under C:\Users\<user name>\Anaconda3\envs\<environment name>\Lib\site-packagesWeihs
same here, the issue started occurring after installing python-certifi-win32. I had to manually remove the package files as suggested by @Richard. Suggest upgrading as @Dentition suggests. Also mentioned in this thread: #51391468Licking
Thanks for this answer. Deleting just python-certifi-win32-init.pth did the job for me. Didn't have to delete distutils-precedence.pth . But what's the workaround now? The main reason why we install python-certifi-win32 is to fix SSLErrors. So what's the alternative?Acoustics
D
14

Andrew Leech, the author of python-certifi-win32, suggests to move on to his other project pip-system-certs (PyPI link). Drop-in replacing python-certifi-win32 with pip-system-certs solved all issues for me.

While the solution provided in this answer prevented the in the question mentioned error message for me too, it came with the side effect that my Python script didn't use the certificates in the Windows certificate store anymore, resulting again in SSL certificate errors - rendering the use of the library useless.

Dentition answered 16/6, 2022 at 15:3 Comment(0)
E
0

The accepted answer did not work for me. For anyone else where it didn't work. If you are using virtual environments, the python-certifi-win32-init.pth file will be located inside the venv folder inside your project. I.e.

venv/Lib/site-packages/python-certifi-win32-init.pth
Erfurt answered 19/9, 2023 at 5:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.