Python Forum
How do I get pygame module to work in Spyder? (Mac)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get pygame module to work in Spyder? (Mac)
#11
(Dec-16-2022, 11:53 PM)snippsat Wrote: Use command line(Terminal) and use command that show.
This is basic stuff How to use the Terminal command line in macOS
I guess you used command line to install pygame?
It is pip install pygame.

Here on Windows the command is same on Mac
# pip version and path it install to
G:\div_code
λ pip -V
pip 22.3 from C:\python310\lib\site-packages\pip (python 3.10)

# Install
G:\div_code
λ pip install pygame
Collecting pygame
  Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
     ---------------------------------------- 8.4/8.4 MB 6.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2
Then path to python is for me(not for you most run same commands).
C:\python310\python that i would set in Spyder.

pygame 2.1.2 is already installed (via terminal).

pygame in "./.local/lib/python3.9/site-packages (2.1.2)"

Edit: I'm trying your solution (properly this time).

Edit2: I can't find the "python3.9" path for my interpreter.
Reply
#12
Then your path in Spyder should be ./.local/lib/python3.9/python
Or it can use /usr/local/lib/python3.9/python,
test with which python or python -c "import sys; print(sys.executable)" to get the correct path.

It will install to ~/.local if you don't have admin right to modify the system-wide /usr/local.
Can use ls -a from command line to see dot directories.
A file explore should show the dot directories.
What is ~/.local folder in Mac OS used for?
Reply
#13
OK so after using "which python" and "python -c "import sys; print(sys.executable)"" the path is shown as:

/opt/miniconda3/bin/python

My current interpreter is set to the above but alas I get a new error message now:

Traceback (most recent call last):
File "/opt/miniconda3/lib/python3.9/site‑packages/spyder_kernels/console/__main__.py", line 24, in
start.main()
File "/opt/miniconda3/lib/python3.9/site‑packages/spyder_kernels/console/start.py", line 328, in main
kernel.initialize()
File "/opt/miniconda3/lib/python3.9/site‑packages/traitlets/config/application.py", line 113, in inner
return method(app, *args, **kwargs)
File "/opt/miniconda3/lib/python3.9/site‑packages/ipykernel/kernelapp.py", line 669, in initialize
self.write_connection_file()
File "/opt/miniconda3/lib/python3.9/site‑packages/ipykernel/kernelapp.py", line 256, in write_connection_file
write_connection_file(
File "/opt/miniconda3/lib/python3.9/site‑packages/jupyter_client/connect.py", line 164, in write_connection_file
with secure_write(fname) as f:
File "/opt/miniconda3/lib/python3.9/contextlib.py", line 119, in __enter__
return next(self.gen)
File "/opt/miniconda3/lib/python3.9/site‑packages/jupyter_core/paths.py", line 898, in secure_write
with os.fdopen(os.open(fname, open_flag, 0o0600), mode, encoding=encoding) as f:
PermissionError: [Errno 13] Permission denied: '/Users/Tony'
Traceback (most recent call last):
File "/opt/miniconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/opt/miniconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/opt/miniconda3/lib/python3.9/site‑packages/spyder_kernels/console/__main__.py", line 24, in
start.main()
File "/opt/miniconda3/lib/python3.9/site‑packages/spyder_kernels/console/start.py", line 328, in main
kernel.initialize()
File "/opt/miniconda3/lib/python3.9/site‑packages/traitlets/config/application.py", line 113, in inner
return method(app, *args, **kwargs)
File "/opt/miniconda3/lib/python3.9/site‑packages/ipykernel/kernelapp.py", line 669, in initialize
self.write_connection_file()
File "/opt/miniconda3/lib/python3.9/site‑packages/ipykernel/kernelapp.py", line 256, in write_connection_file
write_connection_file(
File "/opt/miniconda3/lib/python3.9/site‑packages/jupyter_client/connect.py", line 164, in write_connection_file
with secure_write(fname) as f:
File "/opt/miniconda3/lib/python3.9/contextlib.py", line 119, in __enter__
return next(self.gen)
File "/opt/miniconda3/lib/python3.9/site‑packages/jupyter_core/paths.py", line 898, in secure_write
with os.fdopen(os.open(fname, open_flag, 0o0600), mode, encoding=encoding) as f:
PermissionError: [Errno 13] Permission denied: '/Users/Tony'

I'm not sure how to fix this since my current account is admin.

Thanks for helping me out so far snippsat. I really appreciate it. It's been 2 days since I first stumbled across the pygame issue. Hoping I can resolve it over the weekend and continue learning code afterwards.
Reply
#14
(Dec-17-2022, 03:46 AM)FirstBornAlbratross Wrote: OK so after using "which python" and "python -c "import sys; print(sys.executable)"" the path is shown as:

/opt/miniconda3/bin/python
Now is path set to Miniconda which is fine,but you most know how to use it.
Most activate a environment eg conda activate base if you not have make one.
Most have (base) environment activated,then it will use pip or conda that belong to Miniconda.
Or make new environment as you see in link under
How to Manage Conda Environments on an Apple Silicon M1 Mac

Example is i use (base) environment.
# See that now do pip point to miniconda3
(base) G:\div_code
λ pip -V
pip 21.3.1 from G:\miniconda3\lib\site-packages\pip (python 3.9)

(base) G:\div_code
λ conda -V
conda 4.11.0

# Python point to miniconda3
(base) G:\div_code
λ python -c "import sys; print(sys.executable)"
G:\miniconda3\python.exe

# Will install to this environment
(base) G:\div_code
λ pip install pygame
Collecting pygame
  Downloading pygame-2.1.2-cp39-cp39-win_amd64.whl (8.4 MB)
     |████████████████████████████████| 8.4 MB 3.3 MB/s
Installing collected packages: pygame
Successfully installed pygame-2.1.2

# Start Spyder when enviroment is active
(base) G:\div_code
λ spyder
If you activate the conda environments then usually all will work,but if not activated it will use pip that now is set to a OS python version.
You have installed Python and miniconda versions,but not all get mess together if not activate environment.
Reply
#15
(Dec-17-2022, 11:30 AM)snippsat Wrote:
(Dec-17-2022, 03:46 AM)FirstBornAlbratross Wrote: OK so after using "which python" and "python -c "import sys; print(sys.executable)"" the path is shown as:

/opt/miniconda3/bin/python
Now is path set to Miniconda which is fine,but you most know how to use it.
Most activate a environment eg conda activate base if you not have make one.
Most have (base) environment activated,then it will use pip or conda that belong to Miniconda.
Or make new environment as you see in link under
How to Manage Conda Environments on an Apple Silicon M1 Mac

Example is i use (base) environment.
# See that now do pip point to miniconda3
(base) G:\div_code
λ pip -V
pip 21.3.1 from G:\miniconda3\lib\site-packages\pip (python 3.9)

(base) G:\div_code
λ conda -V
conda 4.11.0

# Python point to miniconda3
(base) G:\div_code
λ python -c "import sys; print(sys.executable)"
G:\miniconda3\python.exe

# Will install to this environment
(base) G:\div_code
λ pip install pygame
Collecting pygame
  Downloading pygame-2.1.2-cp39-cp39-win_amd64.whl (8.4 MB)
     |████████████████████████████████| 8.4 MB 3.3 MB/s
Installing collected packages: pygame
Successfully installed pygame-2.1.2

# Start Spyder when enviroment is active
(base) G:\div_code
λ spyder
If you activate the conda environments then usually all will work,but if not activated it will use pip that now is set to a OS python version.
You have installed Python and miniconda versions,but not all get mess together if not activate environment.

OK, I created a new conda environment called 'myenv' and I have successfully activated it.

I still get the previous "permission" error message though.
Reply
#16
(Dec-17-2022, 06:34 PM)FirstBornAlbratross Wrote: PermissionError: [Errno 13] Permission denied: '/Users/Tony'

I still get the previous "permission" error message though.
Permission denied in Mac Terminal?
Python PermissionError: [errno 13] permission denied Solution
Reply
#17
(Dec-17-2022, 08:08 PM)snippsat Wrote:
(Dec-17-2022, 06:34 PM)FirstBornAlbratross Wrote: PermissionError: [Errno 13] Permission denied: '/Users/Tony'

I still get the previous "permission" error message though.
Permission denied in Mac Terminal?
Python PermissionError: [errno 13] permission denied Solution

This was one of the lines after following the instructions:

drwxr-xr-x 5 root admin 160 9 Nov 21:39 ..

Not sure what to do next as I had trouble following the instructions. (instructions didn't work for me)

I'm also on a Mac if that makes a difference.
Reply
#18
(Dec-17-2022, 06:34 PM)FirstBornAlbratross Wrote: OK, I created a new conda environment called 'myenv' and I have successfully activated it.

I still get the previous "permission" error message though.
How are working with this environment,you most install Spyder and Pygame to this to myenv.
You can not use Spyder that you installed before the can get same problems.
If do this so should the environment bye in user space and should not get permission error..
If still get permission denied on /Users/Tony do this.
sudo chmod -R 755 /Users/Tony

Here from start i make a new my_env and install Spyder and Python 3.10.8 and test that it work.
So this line will install Python 3.10.8 / pip | Spyder and conda.
conda create --name my_env conda spyder python=3.10.8
Now activate environment and install Pygame,see that this is active bye that is show. (my_env)
(my_env) G:\div_code
λ pip install pygame
Collecting pygame
  Using cached pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
Installing collected packages: pygame
Successfully installed pygame-2.1.2
Now start Spyder when environment is activated.
(my_env) G:\div_code
λ spyder
See in image that in point to this environment if not change as descripted before.
So this is all stand alone and what i have install before dos not matter at all,her get new Spyder version and Pygame.
[Image: WRQqmv.png]
Reply
#19
This pygame module has been a total nightmare for me to solve.

I spoke to one of my friends about it and he says I can learn Python without it so that's what I'm going to do.

There's no guarantee that this issue will be resolved in a timely manner and I feel like I'm wasting my time with it all as it's been 3 days since this issue popped up so I'm just going to move on.

Thanks again for all the help.

Edit: Also for the record, the "chmod" code doesn't work for me. No such file or directory.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  keyboard module doesn't work in the microsoft version terminal of python. username 1 2,836 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  pygame music doesn't work CompleteNewb 1 4,657 Jan-30-2021, 09:25 AM
Last Post: Tyrel
  Cannot make 'pandas' module to work... ellie145 2 4,212 Jan-05-2021, 09:38 PM
Last Post: ellie145
  My Python Console doesn´t work ModuleNotFoundError: No module named 'tokenize' RuanKishibe 1 3,155 Aug-06-2020, 10:07 PM
Last Post: deanhystad
  ModuleNotFoundError: No module named 'pygame' Cath 3 14,186 Oct-18-2019, 05:59 PM
Last Post: metulburr
  Pycharm Cannot Find Pygame Module Myang123 2 6,008 Aug-07-2019, 01:26 AM
Last Post: Myang123
  Spyder: Module Not Found jmair 2 20,254 Sep-25-2018, 05:14 PM
Last Post: jmair
  Attribute of module shelve doesn't work Ponomarenko Pavlo 1 5,096 Jul-12-2017, 06:08 PM
Last Post: buran
  Pygame*import pygame ImportError: No module named pygame CASPERHANISCH 1 9,770 Jun-05-2017, 09:50 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020