Karnivaurus
Karnivaurus

Reputation: 24131

ImportError when changing Python interpreter

I have been using PyCharm on Ubuntu to run some Python code, where in Edit Configurations I specified the interpreter path as /usr/bin/python2.7. The code uses the pygame module, and so to install this, I also ran sudo pip install pygame. Then I used import pygame in my Python script, and the file ran ok.

However, I now want to use Python 3.4. So, in PyCharm, I specified the interpreter path to be /usr/bin/python3.4. However, when I run the same file, I now get the error: ImportError: No module named 'pygame'.

Can somebody explain why this is happening? How can I get my Python 3.4 interpreter to find Pygame?

Thanks!

Upvotes: 0

Views: 399

Answers (3)

Nick is tired
Nick is tired

Reputation: 7056

pygame has different releases for each version of Python.

As you have the Python 2.7 module and want to upgrade to Python 3.4, you'll need to reinstall pygame using Python 3.4 instead, you can using pip again or you can download files from here: http://www.pygame.org/download.shtml.

Upvotes: 0

Tagc
Tagc

Reputation: 9072

As others have pointed out, different Python installations will maintain their own independent set of libraries. Bear in mind that you can install packages from the same window that you use to change the interpreter in PyCharm for a project. You might find that more convenient if you're switching between interpreters.

You just click the green 'plus' icon to do so:

Upvotes: 0

blue note
blue note

Reputation: 29099

Each python installation has a separate set of libraries. Your python 3 does not know about Python 2 and its libraries. It seems the default pip command calls the python2 pip script. Run again the pip install, but with the python3 pip (look for it in your python3 folder, it is probably named pip3)

Upvotes: 2

Related Questions