Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[NEED HELP] ImportError PySide2.QtCore



  • Hi everyone,

    I've just installed PySide2 and Shiboken2 by pip install PySide2 command. However, when I try to import PySide2.QtCore, it raised an error ImportError: DLL load failed: The specified procedure could not be found. (I imported PyQt5 and it worked fine)

    35dc9351-5cdc-4e55-bd35-1a9ac523ad28-image.png

    I'm new with PyQt, hope you can help me. Thank you so much.


  • Lifetime Qt Champion

    Hi,

    How did you install Python ?
    Which version is it ?
    Which version of PySide2 is it exactly ?



  • Hi @SGaist ,
    I installed Python in the same folder with Anaconda (C:\) and the version is 3.7
    The version of PySide2 is 5.12.2
    Thanks a lot


  • Lifetime Qt Champion

    @Lucas_1603 said in [NEED HELP] ImportError PySide2.QtCore:

    I installed Python in the same folder with Anaconda (C:)

    This sound a bit frightening. Did you manually install Python on top of anaconda ?



  • @SGaist
    Sorry for the misunderstanding, I installed Python on a separated folder with Anaconda


  • Lifetime Qt Champion

    Ok, did you create a dedicated environment with conda ?
    Do you maybe have both the pip and conda version of PySide2 installed ?
    Any rogue Qt version installed ?



  • @SGaist
    I haven't created any environment with conda yet
    I think pip, conda version and Qt are fine.

    When I install PySide2 via pip, it installed these in Anaconda:

    4a8467e7-ef90-4923-bf2e-f58d68b20232-image.png

    Here is the path to the location of Python:

    e0bdce5e-f5ed-4de3-852a-70e0ad4f48c8-image.png

    PySide2 is installed in Anaconda instead of Python, is that right? Whether it's the reason why Python can't recognize the library?

    Any PATH update or environment is needed? I'm not well aware of those so if yes, please guide me in more detail ^^

    Thank you so much


  • Lifetime Qt Champion

    Something looks strange.

    If you have nothing special in your conda environment, I would reinstall it from scratch and then create a new environment where you will install PySide2. That way you ensure that your environment is clean. You will also be able to inspect it more easily and not mix dependencies you would not need from other environnement.



  • Hi @SGaist ,
    Where should DLL files be and what are they?
    Could I find those DLL files and move or copy them to the right folder?


  • Lifetime Qt Champion

    I do not have a Windows machine at hand but at least on *nix like OSs everything is stored in the sub-folder of the environment you created. That's why I am suggesting to start clean to ensure you do not have stray items. Moving dlls around is rarely the good solution.



  • Hi @SGaist ,
    Actually, I created a new environment by following this guide: https://doc.qt.io/qtforpython-5/quickstart.html
    Here is what I actually did:

    >>> pip uninstall PySide2
    >>> python -m venv env/
    >>> env\Scripts\activate.bat
    >>> pip install PySide2
    

    However, when I import PySide2, it raised an error Modulenotfounderror: NO module named "PySide2"

    My questions are:

    1. Do I need to install anything else in that new environment?
    2. How to check what is the current environment that my program is running?
    3. In case I have more than one environment, how to force the program runs on a specific one (which is the newly created)?

    Thank you so much



  • @Lucas_1603
    Have a look at what is in that env\Scripts\activate.bat. This is what is causing the conda environment to be activated. You will need those settings, whether running your PySide2 program from within an IDE (like Creator) or from a Command Prompt/shortcut icon outside of anything else.



  • Hi @JonB,
    Here is what my env\Scripts\activate.bat looks like:

    @echo off
    
    rem This file is UTF-8 encoded, so we need to update the current code page while executing it
    for /f "tokens=2 delims=:" %%a in ('"%SystemRoot%\System32\chcp.com"') do (
        set "_OLD_CODEPAGE=%%a"
    )
    if defined _OLD_CODEPAGE (
        "%SystemRoot%\System32\chcp.com" 65001 > nul
    )
    
    set "VIRTUAL_ENV=C:\Users\dacluc\env\"
    
    if not defined PROMPT (
        set "PROMPT=$P$G"
    )
    
    if defined _OLD_VIRTUAL_PROMPT (
        set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
    )
    
    if defined _OLD_VIRTUAL_PYTHONHOME (
        set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
    )
    
    set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
    set "PROMPT=() %PROMPT%"
    
    if defined PYTHONHOME (
        set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%"
        set PYTHONHOME=
    )
    
    if defined _OLD_VIRTUAL_PATH (
        set "PATH=%_OLD_VIRTUAL_PATH%"
    ) else (
        set "_OLD_VIRTUAL_PATH=%PATH%"
    )
    
    set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"
    
    :END
    if defined _OLD_CODEPAGE (
        "%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
        set "_OLD_CODEPAGE="
    )
    

    Does it look good? Or does anything need to be modified?
    Thanks a lot


  • Lifetime Qt Champion

    Can you tell me why you use conda for Python but then use the virtualenv module to create environments ?

    It would be simpler to use conda directly for that as well.



  • Hi @SGaist,
    I've just created a new environment using conda and installed everything from scratch, now it works fine
    Thank you so much


Log in to reply