ImportError: /usr/local/lib/python3.2/dist-packages/pygame/base.cpython-32mu.so: undefined symbol: P

在我的ubuntu14.04系统上使用Python3.5安装pygame库时遇到了很多问题,我开始参考了《PYTHON编程:从入门到实践》里提供的安装方法,并不成功,之后在网上找了ubuntu安装pygame的方法如下:
1. Open up the terminal and type the following code:
sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev  libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion  libportmidi-dev
2. Then once all libraries are downloaded and installed, type:
svn co svn://seul.org/svn/pygame/trunk pygame
 cd pygame
 python3 setup.py build
 sudo python3 setup.py install








我按照以上方法执行以后,终端没有报错,但是当import pygame时却出现如下提示:ImportError: /usr/local/lib/python3.2/dist-packages/pygame/base.cpython-32mu.so: undefined symbol: PyCObject_Check










幸好在外网找到一篇帖子,题主遇到的问题和我如出一辙,最后题主找到了解决办法,转载如下:




问题:
So i tried installing pygame using this tutorial:
Code:
Okay, so I struggled for about an hour trying to get ‘ pygame ‘ run  with Python 3 on my ubuntu 11.04 machine, so I decided to write a post  about it.
By default, Ubuntu ships with Python 2.7 installed, so pygame gets installed with python 2.7.
To install it with python3, do the following:
1. Open up the terminal and type the following code:
sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev  libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion  libportmidi-dev
2. Then once all libraries are downloaded and installed, type:
svn co svn://seul.org/svn/pygame/trunk pygame
 cd pygame
 python3 setup.py build
 sudo python3 setup.py install
 3. That’s all! You can now run pygame with python3.
 I have also updated this on the pygame website, so that no one falls into this trouble again! 
And now when i trie to import it i get this:
Code:
Traceback (most recent call last):
  File "", line 1, in
    import pygame
  File "/usr/local/lib/python3.2/dist-packages/pygame/__init__.py", line 95, in
    from pygame.base import *
ImportError: /usr/local/lib/python3.2/dist-packages/pygame/base.cpython-32mu.so: undefined symbol: PyCObject_Check
Please HELP !!


解决方法:
I have pygame for python3.x installed on my desktop, but i redid my laptop and when i tried to install pygame for python3 i had a heck of time doing it. I also installed the python3-dev and sdl dependencies and removed the raw_input() to input(), but kept getting the error the OP stated.


So i checked my desktop and found that i was using pygame 1.9.2 pre and not 1.9.1. So with 1.9.2 pre i got it to to work on my laptop, which was a fresh install of ubuntu.


Here was my process:


0) downloaded 1.9.2 pre which took me a bit just to find:https://launchpad.net/debian/experim...44.orig.tar.gz


1) i had to remove pygame from python3's dist-packages, the pygame directory and the egg-info from 1.9.1
Code:
/usr/local/lib/python3.2/dist-packages
2) installed these (which i know some are non relavent, but i found it and just copied and pasted and installed anyways)
Code:
sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev  libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion  libportmidi-dev
3) then 
Code:
sudo python3 setup.py install
which by the way : no sudo and it will run and execute without errors, but you will still not be able toimport pygame, so sudo it


this is the python version i am using with this also:
Code:
metulburr@ubuntu:~$ python3 --version
Python 3.2.3


you will also get a message saying that some of the dependencies will not run, but i havent had a problem with anything for the past year on the desktop trying to run others programs or writing code myself with anything.


At this point import pygame was successful on my laptop


照题主提供的步骤执行以后,果然可以成功import了。原文网址:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105187214512c7376197974a3ec3933fce240e5c063cbefe6178505380936b6776ed131efdf14234200256b490cc8a4ad9bb866d72c8713b2b43c41c52950eaebb1165817dd04de8df0ee6c9e732e2b9d3a0c854228d0f532dd4abd70d5603ca1eb15f6eb3fbc75f142f07bb9e27658e1b3c78882230eb17a1b76328108086ca5b38d42ba0304bc0fe6c&p=9165c21786cc46e90be2962f49&newp=99769a478f934ea81eaec0395453d8274e3980673ed7c44324b9d71fd325001c1b69e7bd20231605d1c07c6201a94359e8f53178301766dada9fca458ae7c471&user=baidu&fm=sc&query=ImportError%3A+%3A+undefined+symbol%3A+PyCObject%5FCheck&qid=e09bb55d0001db01&p1=1/c?m=9f65cb4a8c8507ed4fece763105187214512c7376197974a3ec3933fce240e5c063cbefe6178505380936b6776ed131efdf14234200256b490cc8a4ad9bb866d72c8713b2b43c41c52950eaebb1165817dd04de8df0ee6c9e732e2b9d3a0c854228d0f532dd4abd70d5603ca1eb15f6eb3fbc75f142f07bb9e27658e1b3c78882230eb17a1b76328108086ca5b38d42ba0304bc0fe6c&p=9165c21786cc46e90be2962f49&newp=99769a478f934ea81eaec0395453d8274e3980673ed7c44324b9d71fd325001c1b69e7bd20231605d1c07c6201a94359e8f53178301766dada9fca458ae7c471&user=baidu&fm=sc&query=ImportError%3A+%3A+undefined+symbol%3A+PyCObject%5FCheck&qid=e09bb55d0001db01&p1=1

你可能感兴趣的:(PYTHON)