How to install pygame in Python3 with pip

2

How can I install pygame for python3 using pip ?. I have the version of Python 3.6.3.

I tried with pip install pygame but it was installed in python 2.7.

Thank you.

    
asked by Patricio Nicolas 27.12.2018 в 17:34
source

4 answers

2

Finally the solutions with:

sudo apt-get install python3-setuptools

sudo easy_install3 pip

sudo pip3.6 install pygame

Source: link

    
answered by 27.12.2018 в 17:41
1

To install pygame, follow these steps:

  • In the Windows command (CMD), focus on the address that contains the Scripts folder, it should be in the same directory where you have installed the python.exe. In my case: C:\Users\Fran\Python\Scripts
  • In CMD, it would be: cd C:\Users\Fran\Python\Scripts

  • Next, use the pip install command, and you're done: pip install Pygame
  • Result:

        
    answered by 27.12.2018 в 17:58
    1

    You say you have python3, but instead pip has installed it for python2, from which it follows that you also have python2.

    The best mechanism for not messing up when you have several versions of python installed on the system is to use a virtual environment . Actually, although the name intimidates a little, it is nothing more than a folder with a specific version of python inside it and in which you can install packages that do not affect the system or other similar folders that you have created for other projects or tests. .

    The steps are very simple:

    Create the folder (virtual environment):

    $ python3 -m venv  ~/entornos/game
    

    This executes python3 (this way you make sure that the virtual environment will be for this version) and loads the venv module, which will create the ~/entornos/game folder and will insert several folders with that version of python and its libraries, as well as an appropriate version of pip . You can call the folder as you like, but it is a good practice to create them all in one place so that it is easy for you to find them. In this case I have assumed that you want to create them all within the entornos folder of your user root directory.

    Activate the environment

    As long as you do not activate the environment, when using from the command line python or pip the system ones will continue to be used. To activate it you must put:

    $ source ~/entornos/game/bin/activate
    

    You will see that your prompt changes and is now (game) $ , as a reminder that you have activated that virtual environment. Now when you do pip install , the pip of that environment will be executed, and what you install will do it within that folder, without affecting the rest of the system. When you execute python the one in that folder will be executed and therefore you will find the packages installed there.

    Deactivate the environment

    When you want to use the system python again (for example, to create another virtual environment), just write:

    (game) $ deactivate
    

    The prompt will return to its normal form to remind you that you are no longer in the virtual environment. The python command will be the system defect again (and you will no longer have access to the packages that you had installed while you were in the virtual environment).

    The environment is also abandoned if you close the terminal. This means that every time you open a new terminal to work in that environment you must activate it again as I indicated above.

        
    answered by 27.12.2018 в 19:00
    0

    You could try

    pip3 install pygame
    

    I hope you find it

        
    answered by 27.12.2018 в 17:38