I am a newbie to python and I am having problems installing pygame? - pygame

I just downloaded pygame 32-bit on a 32-bit macintosh pro. I opened IDLE and typed in import pygame in IDLE shell then click enter. Usually I've heard that it should just return but it gives me the error message.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
Please help me!!!

I can't say if this is a problem of 32/64 bits installation, but you can easily check which version you are running :
import struct; print( 8 * struct.calcsize("P"))

I think it is because you typed py or python3 so it popped up >>> in your terminal so I would download it and do this:
Make sure there is no >>> if there is the only solution I found was the restart the terminal
First download it like this I will be using 3.9 for the version for example:
py -3.9 -m pip install pygame
then use this to check if it downloaded
py -3.9 -m pygame --version
Then open up IDLE - Python [VERSION] and then new file and type import pygame and this should work!

Related

Installation of pyautogui Module fails (I am using python 3.5 32 bit)

Please help. I type pip install pyautogui at the command prompt.
The process begins then stalls. Here is what happens:
C:\Users\alexS\AppData\Local\Programs\Python\Python35-32\Scripts>pip install
pyautogui
Collecting pyautogui
Using cached PyAutoGUI-0.9.33.zip
Collecting pymsgbox (from pyautogui)
Using cached PyMsgBox-1.0.3.zip
Collecting PyTweening>=1.0.1 (from pyautogui)
Using cached PyTweening-1.0.3.zip
Collecting Pillow (from pyautogui)
Using cached Pillow-3.3.1-cp35-cp35m-win32.whl
Collecting pyscreeze (from pyautogui)
Using cached PyScreeze-0.1.8.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\alexS\AppData\Local\Temp\pip-build-1kn1qve4\pyscreeze\se
tup.py", line 6, in <module>
version=__import__('pyscreeze').__version__,
File "C:\Users\alexS\AppData\Local\Temp\pip-build-1kn1qve4\pyscreeze\py
screeze\__init__.py", line 21, in <module>
from PIL import Image
ImportError: No module named 'PIL'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\alexS
\AppData\Local\Temp\pip-build-1kn1qve4\pyscreeze\
C:\Users\alexS\AppData\Local\Programs\Python\Python35-32\Scripts>
Install the Image module first by doing:
$ pip install Image
Then retry installing pyautogui again
This answer is based on experience.
This has been fixed as of 0.9.34, so you should be able to just install it now. Just run pip install -U pyautogui

Pygame installation error says module missing

import os, sys
import pygame
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'
this is the code I tried but this shows these errors
File "D:/Python/sample codes/pygame.py", line 2, in <module> import pygame
File "D:/Python/sample codes\pygame.py", line 3, in <module> from pygame.locals import * ImportError: No module named locals
A.) Have you checked if your version of python corresponds to your version of pygame, or if your version of pygame is 64 or 32 bit(so that it is the same as your computer)
B.) Try to install it again, maybe using the installer again or you could use pip install.
This might help:
(Unable to install Pygame using pip)
The problem here is that the pygame module locals is not installed properly, or at all, so pygame has been installed, but not properly so you must install it again.
Not sure if this helps too much, but I had problems installing pygame. I tend to write code using PyScripter which is a great, easy tool to use.
After lots of issues trying to install pygame, however, I downloaded the 2.7 version (which is available free on their website with all other versions) which came with pygame already installed into the scripter and all modules work perfectly. Maybe this would help!

Installing Cairo and PyCairo Mac OsX

I am playing around with using python iGraph for network visualization. I got his error message when I tried to plot a graph:
>>> layout = g.layout("kk")
>>> plot(g, layout = layout)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/__init__.py", line 446, in plot
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/__init__.py", line 117, in __init__
File "build/bdist.macosx-10.5-x86_64/egg/igraph/drawing/utils.py", line 396, in __getattr__
TypeError: plotting not available
I don't think I installed Cairo or PyCairo correctly.
I am not familiar using Fink or MacPorts, since I commonly use Homebrew.
Any help you be greatly appreciated.
You need to manually compile the library. I used the solution here and just updated the version.
curl -L https://www.cairographics.org/releases/cairo-1.14.6.tar.xz -o cairo.tar.xz
tar -xf cairo.tar.xz && cd cairo-1.14.6
./configure --prefix=/usr/local --disable-dependency-tracking
make install
If while running configure, you get an error about pkg_config, you can install that with brew:
brew install pkg-config
I had the same problem on my MacBook so I wanted to share my solution.
I tried to install pycairo, py2cairo. The installation seemed to be okay but then:
I could not import pycairo
igraph's plot would not work.
The following solved the igraph plotting issue:
sudo pip install cairocffi
or just
pip install cairocffi
So instead of pycairo I used cairocffi and this did the trick.
As Mads said in a comment, brew install cairo works, it solved a related problem for me, so I'm posting here for people who end up here why troubleshooting cairo on OS X.
Accepted answer lead to an error of libpng missing, homebrew on the other hand installed all dependencies correctly.

how to install pygobject for python3 in fedora18

i try to install pygobject for python 3 in fedora 18
i read this doc https://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html and i try to install jhbuild after that when i type $ jhbuild sanitycheck
get this error : bash: jhbuild: command not found...
i try to install with yum , i install "pygobject3-devel" but this not work with python3
in fedora 18 default python is python2.7.3, i install python3.3.0 with yum and test a first demo code :
#!/usr/bin/python
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
after give chmod +x for this python file can run with this command "./test.py"
and if i try to run with python (with out use #! ....) and type this command "$python test.py" that run and work without any problem but when i type this command "$python3 test.py" i get this error :
Traceback (most recent call last):
File "test.py", line 2, in <module>
from gi.repository import Gtk
ImportError: No module named 'gi'
have any idea ?
thanks
Try installing pygobject3 instead of pygobject3-dev (as a matter of fact, it seems that pygobject3 is already installed in a vainilla installation of Fedora).
After installing that package, you should be able to open your interpreter (python2.7) and do:
from gi.repository import Gtk
If you want to use python3 (I didn't understand if you meant that you tried to use python3 or you want to use python3), it seems that the gnome instrospection bindings are not yet available, according to this page that summarizes the state of different packages python3-related that are being on the works.
EDIT: I just tried installing python3-gobject (which should be installed when installing pygobject3, but it doesn't for some reason) and it seems to be working aswell on python3.

Can't import MySQLdb module in Python

I'm trying to use MySQL in Python. I have installed the MySQL adapter (MySQL-python-1.2.4b4.win32-py2.7) for Python, but when I try to import the MySQLdb module (import MySQLdb) with command prompt I receive the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in <module>
import _mysql
ImportError: DLL load failed: %1 is not a valid Win32 application.
Would anybody know, what could be wrong?
You need to have a 32bit version of Python to use this adapter. Which version are you actually using ?
I had problems installing the 64-bit version of MySQLdb on Windows via Pip, but if you want to continue using a 64-bit version of Python, rather than reverting to a 32-bit version, then you can install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/~gohlke/pythonlibs/
You will then want to install the .whl file as document in https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
when you setup the module ,be careful the version ,MySQL-python-1.2.3.win32-py2.7.exe and MySQL-python-1.2.4.win32-py2.7.exe ,only one of the 2 version is you need,try 2 times