首页 > 解决方案 > 如何在 OSX 中将 pygame 安装到我的 vs 代码项目中?

问题描述

我想将 pygame 包添加到我的 vs 代码项目中。我正在使用 OSX,我安装了 pip、python 并下载了 pygame。

但我无法安装它。我阅读了我的控制台日志,但我不知道如何修复它:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pygame
  Using cached https://files.pythonhosted.org/packages/96/e6/a0e790157db7dc6b62192d09a93085bcb2a5261ee45ddc4d6d225ecc4a4d/pygame-1.9.6-cp27-cp27m-macosx_10_11_intel.whl
  Saved ./pygame-1.9.6-cp27-cp27m-macosx_10_11_intel.whl
Successfully downloaded pygame
choehyomin-ui-MacBookPro:~ choihyomin$ pip install pygame
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pygame
  Using cached https://files.pythonhosted.org/packages/96/e6/a0e790157db7dc6b62192d09a93085bcb2a5261ee45ddc4d6d225ecc4a4d/pygame-1.9.6-cp27-cp27m-macosx_10_11_intel.whl
Installing collected packages: pygame
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pygame'
Consider using the `--user` option or check the permissions.

标签: pythonvisual-studio-codepippygame

解决方案


最好的解决方案是创建一个虚拟环境,以便您可以安装到该环境中,而不是全局安装 Python。但如果这不是一个选项,那么错误消息中的建议是有道理的:使用--user

pip install --user pygame

但请确保pip安装您在 VS Code 中选择的 Python 解释器,而不是其他已安装的 Python 副本。如果您不确定,最安全的方法是指定要安装的 Python 解释器:

/path/to/python -m pip install --user pygame

推荐阅读