pythonanacondacondapyside6pythonocc

How to fix issue with QtPdf in Conda environment?


I needed to use python occ so I installed anaconda and now I'm not sure why QtPdf is not working while everything else seems to be fine. I haven't used anaconda before.

Steps:

conda create -n xxxx python=3.10.19
conda activate xxxx
conda install -c conda-forge pythonocc-core
conda install -c conda-forge pyside6
conda install -c conda-forge pandas
conda install -c conda-forge openpyxl

After that I opened my vs studio with code . and checked if right interpreter is in use and ran my script.

It states:

Traceback (most recent call last):
  File "PATH", line 1, in <module>
    from PySide6.QtPdf import QPdfDocument
ModuleNotFoundError: No module named 'PySide6.QtPdf'

This is minimal reproducible example:

from PySide6.QtPdf import QPdfDocument

print("Imported!")

This is just an example script as the issue is the same. When I'm in conda env it's not detecting QtPdf, but if I swap to non conda env it works just fine.

Info:

Pyside6 - 6.8.3
qt6-main 6.8.3
PythonOCC - 7.9.0
Openpyxl - 3.1.5
Pandas - 2.3.3
Python - 3.10.19
conda 25.5.1
OS: win11


Solution

  • I managed to fix the issue stated in my question by doing following:

    I created new conda environment:

    conda create -n xxxx python=3.10.19
    conda activate xxxx
    

    After that I created a pinned in conda-meta, while in your env folder (so check path before creating pinned) with:

    echo %CONDA_PREFIX%
    

    You should see something like this:

    C:\Users\username\AppData\Local\anaconda3\envs\xxxx

    Create pinned file:

    echo qt6-main ==9999> "%CONDA_PREFIX%\conda-meta\pinned"
    

    After creating the pinned file append it with:

    echo qt6-base ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    echo pyside6 ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    echo pyside6* ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    echo vtk ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    echo vtk-base ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    echo wslink ==9999>> "%CONDA_PREFIX%\conda-meta\pinned"
    

    Check pinned file content:

    type "%CONDA_PREFIX%\conda-meta\pinned"
    

    You should see:

    qt6-main ==9999
    qt6-base ==9999
    pyside6 ==9999
    pyside6*
    vtk ==9999
    vtk-base ==9999
    wslink ==9999
    

    After the setup, you can proceed with installation of PythonOCC

    conda install -c conda-forge pythonocc-core
    

    Check and make sure that dependencies from pinned file are not present before typing Y to continue with installation.

    After PythonOCC installation can you install pyside6 by running:

    pip install pyside6==6.8.3
    

    I choose 6.8.3 version because that is the current version which is included when you install PythonOCC from conda-forge