Python3 Linux系统中存在多个python版本 正确安装pygame模块方法

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24909089/article/details/83378073

引导:使用pip安装,pip install pygame,不过此方法会安装到系统默认的python2中,python3依然无法使用

要想安装到相应的python版本中要使用对应的pip 比如安装到python3.6中需要使用pip3.6 install pygame

看下我装了几个版本,好多

xubin@xubindeMBP:~$ python
python             python2.7          python3            python3.6          python3.6m         python3.7          python3.7m         pythonw
python-config      python2.7-config   python3-config     python3.6-config   python3.6m-config  python3.7-config   python3.7m-config  pythonw2.7

安装中可能出现的问题:主要是在python3.6用的时候出现的,又重新装了一个3.7的

问题1:

xubin@xubindeMBP:~$ pip3
Traceback (most recent call last):
  File "/etc/python/python3.6/bin/pip3", line 9, in <module>
    load_entry_point('pip==8.0.2', 'console_scripts', 'pip3')()
  File "/etc/python/python3.6/lib/python3.6/site-packages/setuptools-19.6-py3.6.egg/pkg_resources/__init__.py", line 550, in load_entry_point
  File "/etc/python/python3.6/lib/python3.6/site-packages/setuptools-19.6-py3.6.egg/pkg_resources/__init__.py", line 2710, in load_entry_point
  File "/etc/python/python3.6/lib/python3.6/site-packages/setuptools-19.6-py3.6.egg/pkg_resources/__init__.py", line 2370, in load
  File "/etc/python/python3.6/lib/python3.6/site-packages/setuptools-19.6-py3.6.egg/pkg_resources/__init__.py", line 2376, in resolve
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/__init__.py", line 15, in <module>
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/vcs/subversion.py", line 9, in <module>
    from pip.index import Link
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/index.py", line 29, in <module>
    from pip.wheel import Wheel, wheel_ext
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/wheel.py", line 39, in <module>
    from pip._vendor.distlib.scripts import ScriptMaker
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/_vendor/distlib/scripts.py", line 14, in <module>
    from .compat import sysconfig, detect_encoding, ZipFile
  File "/etc/python/python3.6/lib/python3.6/site-packages/pip-8.0.2-py3.6.egg/pip/_vendor/distlib/compat.py", line 66, in <module>
    from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler'

ImportError: cannot import name 'HTTPSHandler',这个错误表示当前python版本无法加载ssl模块,要重新编译安装解决

解决方式:https://blog.csdn.net/qq_24909089/article/details/83377172

问题2:

xubin@xubindeMBP:/usr/local/python3/Python-3.6.1$ brew reinstall python3 --with-brewed-openssl
==> Reinstalling python
==> Installing dependencies for python: pkg-config, sphinx-doc, gdbm, openssl, readline and sqlite
==> Installing python dependency: pkg-config
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: Failure while executing; `git config --local --replace-all homebrew.private true` exited with 1.
xubin@xubindeMBP:/usr/local/python3/Python-3.6.1$ brew reinstall /usr/local/python3/Python-3.6.1 --with-brewed-openssl
Error: No available formula with the name "/usr/local/python3/Python-3.6.1"
xubin@xubindeMBP:/usr/local/python3/Python-3.6.1$ brew reinstall python3 --with-brewed-openssl
==> Reinstalling python
==> Installing dependencies for python: pkg-config, sphinx-doc, gdbm, openssl, readline and sqlite
==> Installing python dependency: pkg-config
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: Failure while executing; `git config --local --replace-all homebrew.private true` exited with 1.

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun。

xcrun:错误:无效的活动开发者路径(/Library/ developer /CommandLineTools) 这个错误是安装的时候使用的依赖产生的问题

解决方式:https://blog.csdn.net/qq_24909089/article/details/83376244

问题3:

==> Installing python
==> Downloading https://homebrew.bintray.com/bottles/python-3.7.0.mojave.bottle.6.tar.gz
######################################################################## 100.0%
==> Pouring python-3.7.0.mojave.bottle.6.tar.gz
Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /usr/local
Permission denied @ dir_s_mkdir - /usr/local/Frameworks
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

Error: An unexpected error occurred during the `brew link` step

翻译:错误:在“brew link”步骤中发生了意外错误
构建的公式,但没有符号连接到/usr/local
拒绝@ dir_s_mkdir - /usr/local/ framework的权限
错误:拒绝@ dir_s_mkdir - /usr/local/Frameworks权限

是没有Frameworks文件权限,实用的办法是手动创建

解决方式:https://blog.csdn.net/qq_24909089/article/details/83378210

这些都没有问题的话,可正常执行pip3.7 install pygame,安装完成进入python3导入pygame模块查看 没有报错表示成功。

xubin@xubindeMBP:~$ pip3.7 install pygame
Collecting pygame
  Downloading https://files.pythonhosted.org/packages/b9/89/aca02f8771727c2713c11a39c1cc295e4deb60be322be19ad7460570f978/pygame-1.9.4-cp37-cp37m-macosx_10_11_intel.whl (4.9MB)
    100% |████████████████████████████████| 4.9MB 621kB/s
Installing collected packages: pygame
Successfully installed pygame-1.9.4
xubin@xubindeMBP:~$ python3.7
Python 3.7.0 (default, Oct  2 2018, 09:18:58)
[Clang 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> exit();

网站推荐:https://stackoverflow.com/

在这里可以找到更多的问题解决方法,不过都是英文的希望你的浏览器也有翻译功能。

如有不明白的可留言。

猜你喜欢

转载自blog.csdn.net/qq_24909089/article/details/83378073