Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. [NEED HELP] ImportError PySide2.QtCore
Forum Updated to NodeBB v4.3 + New Features

[NEED HELP] ImportError PySide2.QtCore

Scheduled Pinned Locked Moved Solved Qt for Python
15 Posts 3 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Lucas_1603L Offline
    Lucas_1603L Offline
    Lucas_1603
    wrote on last edited by Lucas_1603
    #3

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Lucas_1603L 1 Reply Last reply
      0
      • SGaistS SGaist

        @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 ?

        Lucas_1603L Offline
        Lucas_1603L Offline
        Lucas_1603
        wrote on last edited by
        #5

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          Lucas_1603L 1 Reply Last reply
          0
          • SGaistS SGaist

            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 ?

            Lucas_1603L Offline
            Lucas_1603L Offline
            Lucas_1603
            wrote on last edited by Lucas_1603
            #7

            @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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Lucas_1603L Offline
                Lucas_1603L Offline
                Lucas_1603
                wrote on last edited by
                #9

                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?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Lucas_1603L 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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.

                    Lucas_1603L Offline
                    Lucas_1603L Offline
                    Lucas_1603
                    wrote on last edited by
                    #11

                    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

                    JonBJ 1 Reply Last reply
                    0
                    • Lucas_1603L Lucas_1603

                      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

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #12

                      @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.

                      Lucas_1603L 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @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.

                        Lucas_1603L Offline
                        Lucas_1603L Offline
                        Lucas_1603
                        wrote on last edited by
                        #13

                        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

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          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.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Lucas_1603L 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            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.

                            Lucas_1603L Offline
                            Lucas_1603L Offline
                            Lucas_1603
                            wrote on last edited by
                            #15

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

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved