SoySoy4444
SoySoy4444

Reputation: 450

Install `pygame` with Pip problems

When I run python -V on terminal, it outputs Python 3.8.0 but whenever I try to install a library with pip, it always downloads to Python 3.7.

For example, when I run pip3 install pygame, it outputs Requirement already satisfied: pygame in /usr/local/lib/python3.7/site-packages (1.9.6) but when I test it with import pygame, it returns ModuleNotFoundError: No module named 'pygame'.

I think I installed Python 3.8 incorrectly? I've been using an older version of python with no problems up to now, and I tried installing python 3.8 with pyenv, and ever since then I've had this problem.

My pip is updated: Requirement already up-to-date: pip in /usr/local/lib/python3.7/site-packages (20.0.2)

P.S. Is it just me or do you guys have two folders called Python in both your user library and Macintosh HD library? Also, the 3.7.7 is referring to a totally different folder at Macintosh HD/ussr/local/Cellar/python... is this normal?

Edit: pip3 --version returns pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

Edit 2: Tried using venv. A really long error... (the below error message is only the final part of the actual error message)

ERROR: Command errored out with exit status 1: /Users/username/my_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/g3/8kbv7g411r32xwzp2681_s540000gn/T/pip-install-ywfy_s_y/pygame/setup.py'"'"'; __file__='"'"'/private/var/folders/g3/8kbv7g411r32xwzp2681_s540000gn/T/pip-install-ywfy_s_y/pygame/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/g3/8kbv7g411r32xwzp2681_s540000gn/T/pip-record-fxa7km57/install-record.txt --single-version-externally-managed --compile --install-headers /Users/username/my_venv/include/site/python3.8/pygame Check the logs for full command output.

Edit 3: I just tried reinstalling numpy & pandas & matplotlib, it works with pip3.8 install <library> but pygame doesn't work. Could it be pygame's fault?

Edit 4: Nevermind, I figured it out! Apparently pygame dev 3 wasn't out when Python 3.8 was released, so I have to modify my command to dev 6 with python3 -m pip install pygame==2.0.0.dev6... I don't know why it doesn't fetch the latest version by default but it worked so thank you for your help and time!

Upvotes: 0

Views: 3443

Answers (5)

Dalla Vecchia
Dalla Vecchia

Reputation: 1

Try create a venv with Python 3.7.7. That worked fine for me without any other config.

Upvotes: -1

SoySoy4444
SoySoy4444

Reputation: 450

Posting this to close the question since I've received comments after edit 4.

Apparently pygame dev 3 wasn't out when Python 3.8 was released, so I have to modify my command to dev 6 with python3 -m pip install pygame==2.0.0.dev6... I don't know why it doesn't fetch the latest version by default but it worked.

Upvotes: 1

Biswajit
Biswajit

Reputation: 59

Can you try

pip3 --version

By doing this you will come to know, pip3 is linked to which python interpreter. I think your pip3 is installed for python3.7

If you want to install pygame in python3.8 i will suggest to create an virtualenv for Python3.8 and install there pygame.

To create virtualenv for Python3.8 you can try following command;

# Create a virtualenv 
virtualenv -p /usr/bin/python3.8 venv38

# acticate the enviroment
source venv38/bin/activate

# now you can see somethi like

(venv38) user@mycomputer:~/Desktop/

# install pygame
pip install pygame

Let me know if you need more help.

:)

Upvotes: 1

Haimantika Mitra
Haimantika Mitra

Reputation: 119

I used to face a similar problem with Tensorflow, chances are you have both the versions of python in your system.

Delete the older one and add the latest version to the path. If that does not work, you might consider re-installing.

Upvotes: 1

Tupteq
Tupteq

Reputation: 3105

You should generally use venv library to avoid conflicts and version problems. In your case you should create virtual environment using Python interpreter of choice, then activate it and then install package:

$ python -m venv my_venv
$ source my_venv/bin/activate
(venv)$ pip install pygame

Upvotes: 0

Related Questions