I have a really basic question, pygame isn't being recognized in Windows 7. I have ActiveState Python 2.7 and pygame-1.9.2a0.win32-py2.7.msi installed. However, a simple hello world program that imports pygame gives
Traceback (most recent call last):
File "foo.py", line 1, in <module>
import pygame
ImportError: No module named pygame
Can anyone help me with this? I am not really familiar with editing the PATH if that is what is needed, thanks.
EDIT: Is it because ActiveState is 64 bit and I'm using the 32 bit version of pygame?
Adding pygame to the path is the first thing I would try.
A really simple (and probably bad to leave it there but okay to test) way to get things running is to locate where your pygame is installed, and add it to sys.path
There is more info here: http://greeennotebook.com/2010/06/how-to-change-pythonpath-in-windows-and-ubuntu/
You can eventually add it to the windows PATH.
Ah, never mind, it appears I needed both versions of ActiveState and pygame to be 32 bit. Works now.
Related
I'm pretty frustrated and I'm not even sure where to start. I'm trying to install python arcade and it's going poorly. I'm trying to run one of the tutorial scripts and I get back the following error.
Traceback (most recent call last):
File "", line 4, in
import arcade
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/arcade/init.py", line 103, in
from .drawing_support import calculate_hit_box_points_detailed
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/arcade/drawing_support.py", line 7, in
import pymunkoptions
ModuleNotFoundError: No module named 'pymunkoptions'
pymunk is saying it's installed. Does arcade not work on python 3.9?
I had the same problem.
I got round it by specifying that the version of pymunk needs to be 5.7.0 (apparently it's been updated since 5.7.0 and Arcade still needs to tweak some things to work properly).
In the requirements.txt in Pycharm (if you're following the instructions here: https://arcade.academy/venv_install/index.html), I put both:
arcade
pymunk==5.7.0
Did the trick for me.
File paths were setup incorrectly.
I've been installing, uninstalling, and reinstalling pygame because there's a program that I've been trying to run (that uses pygame). However whenever I've installed pygame, the program doesn't work.
Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\en\snake.py", line 28, in <module>
class Segment(pygame.sprite.Sprite):
AttributeError: 'module' object has no attribute 'sprite'
(Pygame is not installed when I receive this error supposedly)
What's really confusing me though is that when I type import pygame in normally in IDLE, I get no errors even when I just uninstalled it.
Windows 8 64 bit
Python 3.4.3
Pygame-1.9.2a0.win32-py3.4.msi (pygame file name)
Python is installed on C Drive (C:\Python34)
Whenever Pygame was installed, it was on the D drive
Have Python directory added to Path
Here's a screenshot of a video tutorial I was following, and it shows there are two installation paths. And here's mine, which only shows one path. I'm not sure if this is a big deal, but I just want to be sure.
Open your python interpreter and import pygame
Then you can print pygame to see exactly what is being loaded, should be something like: <module 'pygame' from '/Library/Python/2.7/site-packages/pygame/__init__.py'>
(repeat the above step until it fails importing pygame),
Close your prompt and install pygame. Try executing it again. Should the problem persist, you can edit some file in the game you are trying to run and add two lines: import sys and print sys.path and check the list of paths to make sure that there is not some other pygame installation somewhere bundled with the game that is being used instead of your installed pygame.
Modification of Josep Valls's answer:
You will need to change sys.path. This can be accomplished with the following code:
import sys
sys.path.append('''directory where pygame is''')
import pygame
The sys.path variable tell Python where to look for modules. By adding a path by append, you are telling Python to look for imported modules there. After that pointer is made, you can import pygame.
I am working though Zelle's Python book (Python 2.7.5, Canopy Express, Windows 7). For Chapter 5 you need to install his graphics package, graphics.py. I downloaded the current version, put it in the C:\Python27\Lib\site-packages folder and made sure the file has the '.py' extension, but when I type >>import graphics I get the following error in both Canopy and IDLE:
ImportError
Traceback (most recent call last)
<ipython-input-1-e6fd1288a7fc> in <module> ()
----> 1 import graphics
ImportError: No module named graphics
To the best of my knowledge I've followed the instructions and hints on the website and here in StackOverflow, but I'm flummoxed. Any suggestions? I like the Zelle book but I'm not sure how much use it will be from this point on without the graphics package - from just skimming it seems like the majority of the examples and exercises use it. Thanks.
It took a while, but I got it working. Enthought Canopy uses its own (virtual) environments, so you need to put Zelle's graphics package there, not in the system library. I had success by placing graphics in Enthought's top level directory, which you can determine in the interpreter:
>> import site
>> site.getpackages()[0]
I copied the graphics package there, without the .py extension, fired up Canopy and I was off and running. Thanks to everyone who has posted, in various places, tips on importing - eventually it made sense! By the way,
>> site.getpackages()
will give you all site package directories, but I only needed the first.
I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.
How is it possible to run import win32api successfully on a 64bit maya version 2008?
The following error occurs:
Error: No module named win32api
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named win32api
I need to get mouse cursor position in python so that I can place window exactly in that position. Is there any other way to get it?
Best regards,
kNish
Maya uses its own Python installation. You need to add the path where pywin32 is installed by one way or another ... you can create a .pth file in
C:\Program
Files\Autodesk\Maya2009\Python\Lib\site-packages\
Also, like Adam pointed out, make sure you have the 64 bit pywin32 installed.
Here's an article talking about this subject:
http://www.rtrowbridge.com/blog/2008/11/27/maya-python-import-scripts/
Edit:
Yeah indeed I think they don't provide PyWin32 for Python25 x64:
Available for AMD64 versions of
Windows for Python 2.6 and later
(support for Python 2.5 is just too
hard, sorry). Lots of help from
Roger, Steve Yin and Sidnei da
Silva.
http://sourceforge.net/project/shownotes.php?release_id=603349