IT/Python

Python PyQt5 QAxContainer import 에러

상짱 2020. 5. 18. 10:39
반응형

- anaconda / pyCharm 환경

import sys
from PyQt5.QtWidgets import *
from PyQt5.QAxContainer import *

 

- QAxContainer import 에서 에러가 난다.

 

https://stackoverflow.com/questions/56451682/pyqt5-and-anaconda-modulenotfounderror-no-module-named-pyqt5

 

PyQt5 and Anaconda: ModuleNotFoundError: No module named 'PyQt5'

I made a totally new, blank environment in anaconda and activated it. I then did "conda install pyqt5", however when importing modules, like in from PyQt5.QtWidgets import QApplication, QWidget my

stackoverflow.com

- 여기에서 해결점을 찾았다.

 

- 사이트에 있는 해결점 내용

-----------------------------------------------------------------------------------------------------------------------------------

The following worked for me:

  • Install pyqt5 using pip install pyqt5.
  • Then use from PyQt5.QtWidgets import QApplication, QWidget in Python (note the different case!)

UPDATE:

When using virtual environments you have to be sure you are doing all the stuff in the same virtual environment. To do this, first activate your environment, then just use the python command for everything and avoid using the py or pip commands directly.

The following are some steps to help you debugging your problem:

  • First activate your virtual environment. I don't have experience with anaconda, but I assume it's similar to venv or virtualenv (i.e. just calling the corresponding activate script) and you know how to do this.
  • Then:
    • Run python -V to check your Python version.
    • Run python -m pip -V to check the version of PIP. Note that this also prints the location of the pip module. This should be in your virtual environment!
    • Run python -m pip list to see which PIP packages are installed. PyQt5 should be included in this list. If not, run python -m pip install pyqt5 and try again.
    • Run python -m pip show pyqt5 to show information about the pyqt5 module. This also should include a location inside your virtual environment.
    • Run python -c "import PyQt5" to check if the PyQt5 module can be imported. This should print nothing (no ModuleNotFoundError).
    • Run your script using python xyz.py. Don't use the command xyz.py, since in that case the Windows registry determines the "open action", which is likely to run the script using your most recently installed Python version instead of the version from your virtual environment!

-----------------------------------------------------------------------------------------------------------------------------------

 

1. Anaconda Prompt 를 실행한다. ( 윈도우 시작키)

 

2. Anaconda Prompt 콘솔창

# pyqt5 설치
> pip install pyqt5

# 버전체크
> python -V

# pip 버전체크와 경로
> python -m pip -V

# pip 패키지가 설치된 목록
# 목록 중에서 pyqt5 를 확인한다.
> python -m pip list

# 목록중에서 pyqt5 없으면 설치
> python -m pip install pyqt5

# pyqt5 정보를 볼수있고, 경로 확인도 볼수 있다.
> python -m pip show pyqt5

# PyQt5 import 한다. - "여기서 주의점은 대소문자 주의"
> python -c "import PyQt5"

 

짧은 영어지식으로 번역함. ㅎ

 

반응형

'IT > Python' 카테고리의 다른 글

Python / GUI  (0) 2020.05.14
Python / COM  (0) 2020.05.13
7. Python IDE  (0) 2020.02.07
6. Python 파일읽기 / 쓰기  (0) 2020.02.05
5. Python 클래스  (0) 2020.02.04
4. Python 함수와 모듈  (0) 2020.02.04
3. Python 제어문  (0) 2020.01.29
2. Python 기본자료구조(리스트/튜플/딕셔너리)  (0) 2020.01.20
1. Python 변수/문자열/기본데이터타입  (0) 2020.01.20
Python 시작  (0) 2020.01.14