Serial communication with python

Hello,
i am running a python code to read the data from the serial print of the arduino.
i generally work in linux, and the code did work correctly without issues. but when i brought the arduino to a windows pc at work i can not make it work.
the line that fails is this one:

self.serial_port = serial.Serial(port, serialBaud, timeout=1)

port=='COM3'
i can see that the COM3 is the correct one.

  1. i dont have the arduino IDE open when running the script
  2. if i open i can see the serial print for com3
  3. i tried going into the device adiminitrator desactivate the com3, wait, re activate it
  4. i tried to change the com number of the arduino
  5. i tried running inside python debugging from vscode
  6. i tried running from python from powershell
  7. i tried 5 and 6 as admin

non of this gave a solution.
i am always getting:

  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.13_3.13.1520.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 2068, in __call__
    return self.func(*args)
           ~~~~~~~~~^^^^^^^
  File "C:\Users\PC PBR\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
    self._command()
    ~~~~~~~~~~~~~^^
  File "C:\Users\PC PBR\Desktop\franco\tempV4.py", line 265, in start
    self.serial_port = serial.Serial(port, serialBaud, timeout=1)
                       ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC PBR\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\serial\serialwin32.py", line 33, in __init__
    super(Serial, self).__init__(*args, **kwargs)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\PC PBR\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\serial\serialutil.py", line 244, in __init__
    self.open()
    ~~~~~~~~~^^
  File "C:\Users\PC PBR\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\serial\serialwin32.py", line 64, in open
    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': PermissionError(13, 'Accès refusé.', None, 5)

any solution would be appreciated. i am using windows 10 and python 3.13.5

It looks like you are using the serial port in a class, can you show how the port name and the baud rate are assigned and the part that initializes and opens the serial port.

"Access denied" sounds like something else has that com port open.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.