Перейти к содержимому

Как установить pygame в visual studio code

  • автор:

Как установить pygame в vs code

я ввёл, но не сработало

Vitness Просветленный (35043) Алексей Давыдов Жыжнов, на 3.11 нету пайгейма стабильного еще, pip install pygame —pre

Остальные ответы

Похожие вопросы

Ваш браузер устарел

Мы постоянно добавляем новый функционал в основной интерфейс проекта. К сожалению, старые браузеры не в состоянии качественно работать с современными программными продуктами. Для корректной работы используйте последние версии браузеров Chrome, Mozilla Firefox, Opera, Microsoft Edge или установите браузер Atom.

How to import pygame in visual studio code?

I use visual studio code for coding (python) and now I have to write a program with pygame for my project and I can’t import pygame in visual studio code (I can import it with the python script, it just can’t be import ed in visual studio code).

120k 25 25 gold badges 170 170 silver badges 306 306 bronze badges
asked Jan 26, 2019 at 8:15
39 1 1 gold badge 1 1 silver badge 2 2 bronze badges
in console of vscode use this command: pip install pygame
Jan 26, 2019 at 8:20

To elaborate on @Mehrdad’s suggestion: There’s a section on installing matplotlib in the Install and use packages section of the Visual Studio Code Get Started Tutorial. Something similar should work for pygame .

Jan 26, 2019 at 8:44

6 Answers 6

Here is the solution I tried:

From left bottom of your vs code you can find python environment, you can in the image I marked red:

enter image description here

after clicking in the red marked area you can see below option to select:

enter image description here

from the option select your desired one. Suppose first i was try selecting 2nd one but it was not working then i tried with the last one and it worked.

answered Jul 15, 2020 at 20:02
Md Nakibul Hassan Md Nakibul Hassan
2,746 1 1 gold badge 15 15 silver badges 19 19 bronze badges

  1. Open the terminal of Vscode.
  2. Type pip install pygame or pip3 install pygame .
  3. Import pygame and enjoy it.

answered Jun 23, 2019 at 14:31
Mohamadreza Kariminejad Mohamadreza Kariminejad
57 2 2 bronze badges

If it works in the console when you type ‘python yourscript.py’ but not in vs code, you should press ctrl+shift+p and use clic on Python select interpreter to switch to the right env. if it sstill doesn’t work then install the package by running ‘python -m pip install pygame’

answered Jul 17, 2019 at 9:36
305 2 2 silver badges 12 12 bronze badges

Another possible solution is the you could be using VS code in restricted mode. make sure you’re in a trusted browser on the app

answered May 31, 2022 at 19:00
kyle camuti kyle camuti
11 2 2 bronze badges

I have just typed this in VS Code and pygame is installed:

pip3 install pygame 

answered May 9 at 9:31
Moh.Alkasem Moh.Alkasem
11 1 1 bronze badge

Valid and working pygame installation (at the time of posting), using Conda environments and python 3.10:

conda install -c conda-forge pygame 

Using pip as others have suggested should work (in most cases), but if your aim is to have robust dependencies conda is probably a bit better.

Don’t forget to select the interpreter in vs code, it’ll throw errors or simply won’t show up if using pygame packages from other channels, such as this one

Installing Pygame Zero¶

This will also install Pygame. Pre-compiled Pygame packages are available to pip for Windows & Linux (32-bit and 64-bit), and for Mac OS (64-bit only). If you have a different system, you’ll need to find a way to install pygame first. Make sure you are using Python 3 not Python 2.

Mac¶

In a Terminal window, type

pip install pgzero 

Note that there are currently no Wheels for Pygame that support python 3.4 for Mac, so you will need to upgrade Python to >=3.6 (or use python 2.7) in order to be able to install pygame. For a list of available Wheels, please visit pyPI_

Linux¶

In a terminal window, type

sudo pip install pgzero 

Some Linux systems call it pip3 ; if the above command printed something like sudo: pip: command not found then try:

sudo pip3 install pgzero 

Sometimes pip is not installed and needs to be installed. If so try this before running the above commands again:

sudo python3 -m ensurepip 

On Raspberry Pi¶

pgzero has been installed by default since the release of Raspbian Jessie in September 2015!

For flake8/pyflakes¶

Checkers like Pyflakes are unaware of Pygame Zero’s extra builtins.

If you use flake8 , you can add Pygame Zero’s list of builtins to your flake8 configuration file:

[flake8] builtins = Actor,Rect,ZRect,animate,clock,exit,images,keyboard,keymods,keys,mouse,music,screen,sounds,storage,tone 

If you use pyflakes directly then this is configured using the environment variable $PYFLAKES_BUILTINS . On Linux and Mac you could write this in your terminal or put it in your shell configuration file (like ~/.bashrc )

PYFLAKES_BUILTINS=Actor,Rect,ZRect,animate,clock,exit,images,keyboard,keymods,keys,mouse,music,screen,sounds,storage,tone export PYFLAKES_BUILTINS
set PYFLAKES_BUILTINS=Actor,Rect,ZRect,animate,clock,exit,images,keyboard,keymods,keys,mouse,music,screen,sounds,storage,tone

GettingStarted — wiki

Pygame requires Python; if you don’t already have it, you can download it from python.org. It’s recommended to run the latest python version, because it’s usually faster and has better features than the older ones. Bear in mind that pygame has dropped support for python 2.

The best way to install pygame is with the pip tool (which is what python uses to install packages). Note, this comes with python in recent versions. We use the —user flag to tell it to install into the home directory, rather than globally.

python3 -m pip install -U pygame --user

To see if it works, run one of the included examples:

python3 -m pygame.examples.aliens

If it works, you are ready to go! If not there are more detailed, platform-specific instructions further down the page.

Next steps. ¶

  • Having a go at one of the tutorials.
  • Or dive right into the pygame Docs

Further info on installation¶

Hopefully the installation instructions above worked for you. If not, please read some alternative installation methods, and extra details below.

Wheels are available for x86 and x64 architectures on Linux and Windows, and for x64 and arm64 on Mac. If pip doesn’t find a wheel for your platform, it will try to compile pygame from source (see below).

pygame requires a «newer» pip. If pygame starts compiling from source and fails, first try upgrading pip.

Raspberry Pi¶

This comes with pygame already installed on the default raspbian installation. However, it’s an ancient version. Get a newer pygame.

python3 -m pip install -U pygame --user

Windows installation¶

Make sure you install python with the «Add python to PATH» option selected. This means that python, and pip will work for you from the command line.

There is documentation with python for the «windows installation steps»

py -m pip install -U pygame --user
py -m pygame.examples.aliens

If you get ‘PermissionError: [WinError 5] Access is denied’, before starting the command prompt right click and «Run as administrator».

Mac installation¶

Recent versions of Mac OS X require pygame 2¶

If your examples aren’t running and you are using a recent version of Mac OS X; try this line to install pygame instead:

python3 -m pip install -U pygame --user
Anaconda Mac¶
pythonw
python

(note the w on the end). If it doesn’t work for you, please see the /wiki/MacCompile instructions.

Unix Binary Packages¶

Many Linux and BSD distributions have their own packages of Pygame. These may have an older version of Pygame than the wheels, but have been carefully tested with other packages in that distribution.

Debian/Ubuntu/Mint¶
sudo apt-get install python3-pygame
python3 -m pygame.examples.aliens
Fedora/Red hat¶
sudo yum install python3-pygame
python3 -m pygame.examples.aliens
OpenSUSE¶
sudo zypper install python3-pygame

Arch/Manjaro

sudo pamac install python-pygame
python -m pygame.examples.aliens
Distribution Python 3 package Debian/Ubuntu python3-pygame Fedora python3-pygame

FreeBSD also has an active pygame package. While techinicaly it isn’t binary, it is automatically built and installed by the ports manager. See the FreeBSD package page for more information. http://www.freebsdports.info/ports/devel/py-game.html

Gentoo has a builtin package for pygame. This is compiled for your system as it installs, similar to BSD, http://packages.gentoo.org/package/dev-python/pygame

Installing From Source¶

Compilation¶

Compiling and installing pygame is handled by Python’s distutils. Pygame also comes with some scripts to automatically configure the flags needed to build pygame. Use the «setup.py» script to start the installation.

The first time you run the setup script, it will call the «config.py» script. This will build a «Setup» file which stores all the information needed to compile. The «config.py» will do a good job of detecting what dependencies are available and where they are located. If it isn’t perfect, it is easy to build your own, or edit the created «Setup» text file. This «Setup» file is a simple Makefile-like text file. It defines variables needed to use each dependency, and then enables all the pygame modules with found dependencies. If you have trouble compiling, you should be able to easily fix any problems inside the «Setup» file.

Running the «setup.py» script will call distutils to build and install the pygame package. Distutils actually supports a wide variety of compile and install options. running «python setup.py help» will start to show you the different options available. You can change many things like install locations, compiler to use, and more. Calling the «setup.py» script with no arguments and it will just ask you if you want the default flags needed to compile and install.

Some of the .c files are generated by Cython from .pyx files. Running «setup.py cython» will update them.

Windows Compiling Info

You can compile pygame on windows with mingw (gcc for windows) and also with visual studio. Up to date details can be found here: CompileWindows

Unix Compiling Info

Compiling from linux shouldn’t give you any problems. One thing you must keep in mind is that most linux RPM packages separate the actual library from the «dev» files needed to compile. To build you will need to make sure the packages like «SDL-dev» are installed.

You can check to see if SDL is ready to be built from by running the command sdl-config and seeing if it is found. If the sdl-config script is not on the path (or you have more than one?) Set the environment variable SDL_CONFIG to its location.

Sometimes you will have the SDL libraries installed in once location, and the other SDL libraries in another. This tricks the pygame config scripts, but you can help it out by setting the environment LOCALBASE to a path prefix where the other libraries are. The common case for this is SDL installed in /usr and other SDL libs installed in /usr/local. The command for this situation is «LOCALBASE=/usr/local python setup.py install«.

Mac OS X Compiling Info¶

Up to date instructions for compiling on Mac OS X can be found here: MacCompile

if anaconda is installed¶

please deactivate base by:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *