简体   繁体   English

安装 `pygame` 出现 Pip 问题

[英]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. 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' . 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?我想我错误地安装了 Python 3.8? 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.我一直在使用旧版本的 python 到目前为止没有任何问题,我尝试使用 pyenv 安装 python 3.8,从那时起我就遇到了这个问题。

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

PS Is it just me or do you guys have two folders called Python in both your user library and Macintosh HD library? PS是只有我还是你们在您的用户库和Macintosh HD库中有两个名为Python的文件夹? Also, the 3.7.7 is referring to a totally different folder at Macintosh HD/ussr/local/Cellar/python ... is this normal?此外,3.7.7 指的是Macintosh HD/ussr/local/Cellar/python上完全不同的文件夹……这正常吗?

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

Edit 2: Tried using venv .编辑 2:尝试使用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. 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?这可能是pygame的错吗?

Edit 4: Nevermind, I figured it out.编辑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 so thank you for your help and time! 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默认情况下不会获取最新版本,但它可以工作,所以感谢您的帮助和时间!

Can you try你能试一下吗

pip3 --version

By doing this you will come to know, pip3 is linked to which python interpreter.通过这样做你会知道,pip3 链接到哪个 python 解释器。 I think your pip3 is installed for python3.7我认为你的 pip3 是为 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.如果你想在 python3.8 中安装 pygame,我建议为 Python3.8 创建一个 virtualenv 并在那里安装 pygame。

To create virtualenv for Python3.8 you can try following command;要为 Python3.8 创建 virtualenv,您可以尝试以下命令;

# 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.如果您需要更多帮助,请告诉我。

:) :)

I used to face a similar problem with Tensorflow, chances are you have both the versions of python in your system.我曾经在 Tensorflow 遇到过类似的问题,很可能您的系统中同时拥有 python 的两个版本。

Delete the older one and add the latest version to the path.删除旧版本并将最新版本添加到路径中。 If that does not work, you might consider re-installing.如果这不起作用,您可能会考虑重新安装。

Posting this to close the question since I've received comments after edit 4.发布此问题以关闭问题,因为我在编辑 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. 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'默认情况下获取最新版本,但它可以工作。

You should generally use venv library to avoid conflicts and version problems.您通常应该使用venv库来避免冲突和版本问题。 In your case you should create virtual environment using Python interpreter of choice, then activate it and then install package:在您的情况下,您应该使用选择的 Python 解释器创建虚拟环境,然后激活它,然后安装 package:

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

Try create a venv with Python 3.7.7.尝试使用 Python 3.7.7 创建一个 venv。 That worked fine for me without any other config.没有任何其他配置,这对我来说很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM