ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Unable to import 'streamlit' 오류 해결 방법
    Coding 2023. 11. 15. 21:21

    pythonStreamlit을 웹 어플리케이션 프로젝트를 시작해보기 위해 진행하던 도중 나온

    에러 메시지

    [{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "E0401:import-error",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/error/import-error.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 8,
    	"message": "Unable to import 'streamlit'",
    	"source": "Pylint",
    	"startLineNumber": 1,
    	"startColumn": 1,
    	"endLineNumber": 1,
    	"endColumn": 23
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "E0401:import-error",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/error/import-error.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 8,
    	"message": "Unable to import 'pandas'",
    	"source": "Pylint",
    	"startLineNumber": 2,
    	"startColumn": 1,
    	"endLineNumber": 2,
    	"endColumn": 20
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "E0401:import-error",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/error/import-error.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 8,
    	"message": "Unable to import 'numpy'",
    	"source": "Pylint",
    	"startLineNumber": 3,
    	"startColumn": 1,
    	"endLineNumber": 3,
    	"endColumn": 19
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "W0611:unused-import",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/warning/unused-import.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 4,
    	"message": "Unused streamlit imported as st",
    	"source": "Pylint",
    	"startLineNumber": 1,
    	"startColumn": 1,
    	"endLineNumber": 1,
    	"endColumn": 23
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#3",
    	"code": {
    		"value": "reportMissingImports",
    		"target": {
    			"$mid": 1,
    			"path": "/microsoft/pyright/blob/main/docs/configuration.md",
    			"scheme": "https",
    			"authority": "github.com",
    			"fragment": "reportMissingImports"
    		}
    	},
    	"severity": 4,
    	"message": "Import \"streamlit\" could not be resolved",
    	"source": "Pylance",
    	"startLineNumber": 1,
    	"startColumn": 8,
    	"endLineNumber": 1,
    	"endColumn": 17
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "W0611:unused-import",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/warning/unused-import.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 4,
    	"message": "Unused pandas imported as pd",
    	"source": "Pylint",
    	"startLineNumber": 2,
    	"startColumn": 1,
    	"endLineNumber": 2,
    	"endColumn": 20
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#3",
    	"code": {
    		"value": "reportMissingModuleSource",
    		"target": {
    			"$mid": 1,
    			"path": "/microsoft/pyright/blob/main/docs/configuration.md",
    			"scheme": "https",
    			"authority": "github.com",
    			"fragment": "reportMissingModuleSource"
    		}
    	},
    	"severity": 4,
    	"message": "Import \"pandas\" could not be resolved from source",
    	"source": "Pylance",
    	"startLineNumber": 2,
    	"startColumn": 8,
    	"endLineNumber": 2,
    	"endColumn": 14
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "W0611:unused-import",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/warning/unused-import.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 4,
    	"message": "Unused numpy imported as np",
    	"source": "Pylint",
    	"startLineNumber": 3,
    	"startColumn": 1,
    	"endLineNumber": 3,
    	"endColumn": 19
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#3",
    	"code": {
    		"value": "reportMissingImports",
    		"target": {
    			"$mid": 1,
    			"path": "/microsoft/pyright/blob/main/docs/configuration.md",
    			"scheme": "https",
    			"authority": "github.com",
    			"fragment": "reportMissingImports"
    		}
    	},
    	"severity": 4,
    	"message": "Import \"numpy\" could not be resolved",
    	"source": "Pylance",
    	"startLineNumber": 3,
    	"startColumn": 8,
    	"endLineNumber": 3,
    	"endColumn": 13
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "W0611:unused-import",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/warning/unused-import.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 4,
    	"message": "Unused sleep imported from time",
    	"source": "Pylint",
    	"startLineNumber": 5,
    	"startColumn": 1,
    	"endLineNumber": 5,
    	"endColumn": 23
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "C0114:missing-module-docstring",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/convention/missing-module-docstring.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 2,
    	"message": "Missing module docstring",
    	"source": "Pylint",
    	"startLineNumber": 1,
    	"startColumn": 1,
    	"endLineNumber": 1,
    	"endColumn": 1
    },{
    	"resource": "/C:/streamlit_web/app.py",
    	"owner": "_generated_diagnostic_collection_name_#2",
    	"code": {
    		"value": "C0411:wrong-import-order",
    		"target": {
    			"$mid": 1,
    			"path": "/en/latest/user_guide/messages/convention/wrong-import-order.html",
    			"scheme": "https",
    			"authority": "pylint.readthedocs.io"
    		}
    	},
    	"severity": 2,
    	"message": "standard import \"from time import sleep\" should be placed before \"import streamlit as st\"",
    	"source": "Pylint",
    	"startLineNumber": 5,
    	"startColumn": 1,
    	"endLineNumber": 5,
    	"endColumn": 23
    }]

     

    이렇게 나온 에러를 정리해보면

     

    E0401:import-error (Pylint)

     

    Message: Unable to import 'streamlit'

    This message indicates that there is an import error for the 'streamlit' module. Your code is trying to import 'streamlit,' but it can't find the module.

    E0401:import-error (Pylint)

     

    Message: Unable to import 'pandas'

    Similar to the first message, this one indicates an import error for the 'pandas' module.

    E0401:import-error (Pylint)

     

    Message: Unable to import 'numpy'

    This message points out an import error for the 'numpy' module.

    W0611:unused-import (Pylint)

     

    Message: Unused streamlit imported as st

    This is a warning that the 'streamlit' module has been imported as 'st' but is not used in your code.

    reportMissingImports (Pylance)

     

    Message: Import "streamlit" could not be resolved

    Pylance is reporting that it couldn't resolve the import statement for 'streamlit,' which means it doesn't recognize it as a valid module.

    W0611:unused-import (Pylint)

     

    Message: Unused pandas imported as pd

    Similar to message 4, this is a warning that the 'pandas' module has been imported as 'pd' but is not used in your code.

    reportMissingModuleSource (Pylance)

     

    Message: Import "pandas" could not be resolved from source

    Pylance is reporting that it couldn't resolve the import statement for 'pandas' from its source.

    W0611:unused-import (Pylint)

     

    Message: Unused numpy imported as np

    Similar to message 4 and 6, this is a warning that the 'numpy' module has been imported as 'np' but is not used in your code.

    reportMissingImports (Pylance)

     

    Message: Import "numpy" could not be resolved

    Pylance is reporting that it couldn't resolve the import statement for 'numpy.'

    W0611:unused-import (Pylint)

     

    Message: Unused sleep imported from time

    This is a warning that the 'sleep' function from the 'time' module has been imported but is not used in your code.

    C0114:missing-module-docstring (Pylint)

     

    Message: Missing module docstring

    Pylint is suggesting that you add a docstring at the module level to provide documentation for your module.

    C0411:wrong-import-order (Pylint)

     

    Message: Standard import "from time import sleep" should be placed before "import streamlit as st"

    Pylint is recommending that you reorder your import statements so that standard library imports come before third-party imports.

     

    정리 된다.

     

    해결 방법

     

    1. 모듈 설치: 먼저, 사용하려는 모듈이 설치되어 있는지 확인하십시오. 필요한 모듈이 설치되지 않은 경우, pip 또는 conda를 사용하여 모듈을 설치하세요. 예를 들어, 'streamlit', 'pandas', 'numpy'를 설치하려면 다음과 같이 명령을 실행할 수 있습니다:
    pip install streamlit pandas numpy
    1. 불필요한 Import 제거: Pylint가 보고한 불필요한 Import 문제를 해결하세요. 사용하지 않는 import 문장을 제거하거나 필요한 곳에서 해당 모듈을 사용하세요.
    2. Import 순서 조정: Pylint가 보고한 잘못된 Import 순서 문제를 해결하세요. 표준 라이브러리(import time)와 서드파티 라이브러리(import streamlit) 순서를 맞추세요.
    3. 문서화 추가: Pylint가 보고한 모듈 레벨의 docstring 부족 문제를 해결하세요. 모듈에 설명을 추가하여 코드 문서화를 개선하세요.
    4. IDE 설정 검토: IDE(통합 개발 환경) 설정을 검토하여 오류 메시지를 줄일 수 있는 방법을 찾으세요. IDE 설정을 최적화하면 코드 분석 도구가 더 정확한 결과를 제공할 수 있습니다.
    5. Import 경로 확인: 모듈의 실제 위치를 확인하고 import 경로를 정확하게 지정하세요. 경로가 올바른지 확인하고 필요한 경우 수정하세요.
    6. Pylint 설정 조정: Pylint의 설정 파일을 사용하여 오류와 경고 메시지를 사용자 정의하세요. 일부 오류나 경고를 무시하거나 숨기는 것도 가능합니다. Pylint 설정 파일을 수정하여 프로젝트에 맞게 설정하세요.
    7. 파이썬 버전 확인: 사용 중인 파이썬 버전과 모듈의 버전이 호환되는지 확인하세요. 일부 모듈은 특정 파이썬 버전과 호환되지 않을 수 있습니다.

     

    위의 단계를 따르면 오류 메시지를 해결할 수 있을 것입니다. 그러나 구체적인 코드와 환경에 따라 상세한 해결 방법이 다를 수 있으므로, 보다 구체적인 도움을 원한다면 코드와 사용 중인 개발 환경에 대한 자세한 정보를 제공해 주시면 추가적인 지원을 제공할 수 있습니다.

     

    1번을 진행할 때 WARNING: Ignoring invalid distribution -cipy (c:\python38-64\lib\site-packages) 이런 메시지가 나오면

     

    "WARNING: Ignoring invalid distribution" 오류는 파이썬 패키지 관리자(pip)가 패키지 배포를 설치하려고 시도했지만, 설치하려는 배포가 유효하지 않을 때 발생할 수 있습니다. 이러한 문제는 배포의 손상된 버전이 설치되어 있거나, 다른 이유로 인해 패키지가 제대로 설치되지 않았을 때 발생할 수 있습니다.

     

    이것에 대한 해결 방안은

     

    1. 파이썬 환경 업데이트:

    먼저 파이썬과 pip를 최신 버전으로 업데이트하세요. 다음 명령어를 사용하여 파이썬을 업데이트합니다:

    pip install --upgrade pip

    그리고 파이썬도 최신 버전으로 업데이트하십시오.

     

    2. 유효하지 않은 패키지 제거:

    오류 메시지에서 보고된 유효하지 않은 배포(cipy)를 제거하세요. 다음 명령어를 사용하여 해당 패키지를 삭제합니다:

    pip uninstall cipy

     

    그런 다음, 필요한 패키지를 다시 설치하세요.

     

    3. 가상 환경 사용:

    프로젝트별로 가상 환경을 사용하여 패키지 관리를 분리할 수 있습니다. 가상 환경을 생성하고 활성화한 후, 패키지를 설치하세요. 가상 환경을 사용하면 전역 파이썬 환경에 영향을 주지 않고 패키지를 관리할 수 있습니다.

    python -m venv myenv # 가상 환경 생성
    myenv\Scripts\activate # 가상 환경 활성화 (Windows)
    pip install streamlit pandas numpy # 필요한 패키지 설치

     

    4. 파이썬 환경 재설정:

    만약 위의 단계가 해결책이 되지 않는다면, 파이썬 환경을 완전히 재설정하는 것을 고려할 수 있습니다. 파이썬을 삭제하고 다시 설치한 다음, 필요한 패키지를 재설치하세요.

     

    주의: 파이썬을 재설치할 때 현재 프로젝트와 라이브러리를 백업하고 다시 복원해야 합니다.

     

Designed by Tistory.