글의 방향성
필자가 실제 pygame을 실행하면서 겪은 문제들을 순서대로 해결하는 것이라, 순서가 섞여있어 복잡할 수 있음을 양해 부탁드린다.
필자의 폴더 구성 설명
필자는 C드라이브 용량 문제로 D드라이브에 ProgramFiles라는 폴더를 생성 후 해당 폴더에 각 프로그램에 맞는 폴더를 생성후 관리한다.
D드라이브 ProgramFiles 폴더 구성
-anaconda3 : 아나콘다 3.8 버전을 다운했다.
-python : 파이썬 3.9.1 버전을 다운했다.
참고. anaconda3 폴더 구성
python 폴더 및 anaconda3 폴더는 필자가 임의로 설정한 이름이고 그 안에 설치된 자료는 디폴드 경로로 다운 받은 내용과는 동일하다. 이때 Scripts 파일에 pygame을 설치할 것이다.
문제1. 에디터 별로 Pygame의 실행 성공 여부 다름
Pygame을 실행할 때 Visual Studio Code에서 실행이 되지만, Spyder에서 실행되지 않는 문제가 발생했다.
ModuleNotFoundError: No module named 'pygame' 가 Syder 터미널 창에 뜸.
원인1. pygame이 설치된 경로가 python 폴더였다.
pygame이 에디터에서 실행되는 장소와 설치된 장소가 달라서 오류가 난 것이다.
처음에 Pygame 본인 파이썬 (3.9.1)버전에 맞는 pygame-2.0.1-cp-cp39-win_amd64.whl 가 다운로드 되었다.
이때 cp39는 파이썬 버전을 의미한다. 파이썬 3.9 버전은 pygame c39, 파이썬 3.8 버전은 pygame 3.8버전을 의미.
문제2. 파이썬 해석기가 conda 환경인데, 활성화 되어있지 않음.
This Python interpreter is in a conda environment, but the environment has
not been activated.
해결2. 자신이 anaconda를 설치한 폴더의 Sciprt폴더에 activate base 하면 됨
D:\ProgramFiles\anaconda3\Scripts>D:\ProgramFiles\anaconda3\Scripts\activate base 입력.
에서 \Scipts\activate base 는 경로 불문 동일하다.
해결1. python 폴더가 아닌 아나콘다가 설치된 폴더안의 Scripts 폴더에 pygame을 설치
D:\ProgramFiles\anaconda3\Scripts>pip3 install pygame 입력.
pip3 를 해줘야 파이썬 3.X 버전으로 설치된다.
anaconda3의 Scipts 폴더안에 pygame을 설치해야함
anaconda3의 3.8.5 버전에 의해 pygame cp38 설치
D:\ProgramFiles\anaconda3\Scripts>D:\ProgramFiles\anaconda3\Scripts\activate base
(base) D:\ProgramFiles\anaconda3\Scripts>python
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
(base) D:\ProgramFiles\anaconda3\Scripts>pip3 install pygame
Collecting pygame
Downloading pygame-2.0.1-cp38-cp38-win_amd64.whl (5.2 MB)
|████████████████████████████████| 5.2 MB 1.6 MB/s
Installing collected packages: pygame
Successfully installed pygame-2.0.1
(base) D:\ProgramFiles\anaconda3\Scripts>
Spyder에서 Pygame이 import 되어 실행됨을 확인할 수 있다.
Visual Studio Code에서 import pygame 성공하여 Hello from the pygame이 된 것을 확인할 수 있다.
'Python' 카테고리의 다른 글
[Python] 파이썬 webbrowser URL 열기 크롬으로 변경 (0) | 2021.02.21 |
---|---|
[Anaconda] 아나콘다 D드라이브 다운로드 방법 및 과정 (0) | 2021.02.04 |
댓글