ImportError: No module named PyQt4

后端 未结 5 583
悲哀的现实
悲哀的现实 2020-12-15 17:09

I installed pyqt4 by using Homebrew. But when I import PyQt4 in python interpreter, It said that \"No module named PyQt4\". Can somebody help me with that?

5条回答
  •  执念已碎
    2020-12-15 17:23

    You have to check which Python you are using. I had the same problem because the Python I was using was not the same one that brew was using. In your command line:

    1. which python
      output: /usr/bin/python
    2. which brew
      output: /usr/local/bin/brew     //so they are different
    3. cd /usr/local/lib/python2.7/site-packages
    4. ls   //you can see PyQt4 and sip are here
    5. Now you need to add usr/local/lib/python2.7/site-packages to your python path.
    6. open ~/.bash_profile   //you will open your bash_profile file in your editor
    7. Add 'export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH' to your bash file and save it
    8. Close your terminal and restart it to reload the shell
    9. python
    10. import PyQt4    // it is ok now

提交回复
热议问题