Pyside6 and pywin32 cannot be imported simultaneously

24 views Asked by At

As a beginner in PySide6, I'm currently developing an application where I use the pywin32 package to read doc files. However, when I import both win32com.client and packages related to PySide6, I encounter the following error. enter image description here

PS C:\Users\xiaowu\VSCodeProjects> & C:/Users/xiaowu/anaconda3/envs/pyside6/python.exe c:/Users/xiaowu/VSCodeProjects/Draft/Demo1.py
Traceback (most recent call last):
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\tokenize.py", line 330, in find_cookie
    line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\xiaowu\VSCodeProjects\Draft\Demo1.py", line 2, in <module>
    import win32com.client
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\site-packages\win32com\__init__.py", line 6, in <module>
    import pythoncom
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\site-packages\pythoncom.py", line 2, in <module>    
    import pywintypes
  File "shibokensupport/signature/loader.py", line 61, in feature_imported
  File "shibokensupport/feature.py", line 137, in feature_imported
  File "shibokensupport/feature.py", line 148, in _mod_uses_pyside
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\inspect.py", line 1024, in getsource
    lines, lnum = getsourcelines(object)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\inspect.py", line 1006, in getsourcelines
    lines, lnum = findsource(object)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\inspect.py", line 831, in findsource
    lines = linecache.getlines(file, module.__dict__)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\linecache.py", line 46, in getlines
    return updatecache(filename, module_globals)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\linecache.py", line 136, in updatecache
    with tokenize.open(fullname) as fp:
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\tokenize.py", line 394, in open
    encoding, lines = detect_encoding(buffer.readline)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\tokenize.py", line 371, in detect_encoding
    encoding = find_cookie(first)
  File "C:\Users\xiaowu\anaconda3\envs\pyside6\lib\tokenize.py", line 335, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'C:\\Users\\xiaowu\\anaconda3\\envs\\pyside6\\lib\\site-packages\\pywin32_system32\\pywintypes39.dll'

If someone could help me with this, I would be extremely grateful. Thank you very much!

I removed all other packages and kept only the ones related to PySide6 and pywin32, but the program still throws errors. This convinces me that there is a conflict between these two packages. I've searched online and tried changing the encoding to UTF-8, but the error persists.

0

There are 0 answers