Search code examples
pythonimportlibraries

Python Libraries can't be detected


I installed some python libraries, but they can't be detected. In pycharm they are orange so excluted and Visual Studio Code says "Import "cv2" could not be resolved" if I want to include open cv. I also had 3 Versions of Python at first, but now I only have one left is that a problem?

Deleted old Versions of Python and Anaconda was the only thing that made the pip comand work again. I looked up if everything is installed with "pip list".


Solution

  • You need to have the installed python in your path. The first interpreter it reaches in path will be used, if not just add it to your path

    where.exe python
    C:\dist\venvs\trk-fullstack-test\Scripts\python.exe
    C:\dist\Python310\python.exe
    C:\Users\mobj\AppData\Local\Microsoft\WindowsApps\python.exe
    
    $ENV:PATH = "C:\dist\Python310;$ENV:PATH"
    
    where.exe python
    C:\dist\Python310\python.exe
    C:\dist\venvs\trk-fullstack-test\Scripts\python.exe
    C:\Users\mobj\AppData\Local\Microsoft\WindowsApps\python.exe
    

    All modules installed with pip will follow the python interpreter used.

    Recommend taking a look a https://docs.python.org/3/library/venv.html to see how virtual environments are handled.