Pygame missing modlues - python-2.7

Im completely new to pygame. after installing it and looking at a tutorial, the first code block i ran (from the tutorial) took me to the pygame modlule, and said that pygame.base could not be found.
it couldn't find any of these at all:
from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
from pygame.compat import geterror
import pygame.rwobject
import pygame.surflock
import pygame.color
that's from the pygame module.
I looked in both the pygame files that were installed and saw files with those names, though i could not open them (unknown file type)
i installed the python 2.7 binary for windows version of pygame, and used the installer. everything looks like it's in the right place as far as i can tell.

It doesn't seem that you have pygame properly installed. Can you even successfully run import pygame?
Are you sure you only have one copy of python installed?

Related

ImportError: No module named vaderSentiment

I'm trying to run a code in python2.7 on windows os that uses sentiment analysis
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
and I'm getting this error
ImportError: No module named vaderSentiment
Can anyone help me with this?
Assuming you solved this one as it's from 7 months ago, but for anyone else searching for it:
Go into terminal/cmd and paste the following:
pip install vaderSentiment
More info on VADER: https://github.com/cjhutto/vaderSentiment
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
#note: depending on how you installed (e.g., using source code download versus pip install), you may need to import like this:
#from vaderSentiment import SentimentIntensityAnalyzer
read the comment in a code
Try running your file with Python3 instead of just python. Sometimes when you have different pips/pythons installed on your computer you might have vaderSentiment installed in python2 when you need to run it in python3.

cannot import name module with module correctly installed

new in python.
I have python 2.7.
I just installed a new module (beatifulsoup) from cmd in windows 7 which is correctly installed : When I enter the python consol from the cmd I can import succesfully bs4 without error.
My problem is that I cannot import it when I am using Aptana studio. Or if I code it in sublimetext and save it as a py file, when I run it I get the error message "cannot import name beautifulsoup 4". I don't get why? Is it a problem of pydev environment on aptana? If yes how can I add modules to Aptana and sublimetext3 ?
Are you trying to import like this:
from bs4 import BeautifulSoup
If not, try it that way. Hope this helps!
(Perhaps you should add your import statement to the question so we can see if there is a problem with the statement or if the issue resides somewhere else)

How to properly install pygame module in windows? And make games

I have written codes but it's showing cannot import pygame module
Download pygame from here: http://www.pygame.org/download.shtml
If you are not sure which version of python you are running, execute the following code in your shell:
import sysconfig
version = sysconfig.get_python_version()
print(version) #Python3
print version #Python2
Usually, Python3 will also accept the print command without brackets, so using sysconfig is the safest way. Sysconfig will also tell you which minor version you are using (such as 3.4.5)
Once you have download pygame, tryimport pygame in your shell. If this does not work, type help('modules'). This will now list all your modules. If pygame is not in there, check in which folder all other modules are saved and move the pygame module to that file path.
You can also use sysconfig to display all the file paths python is using:
import sysconfig
paths = sysconfig.get_paths()
print(paths) #For Python2, see print method above
I don't quite understand what you mean with "And make games", but the pygame website has a great documentary and some example codes to help you learn progamming with the pygame module.
Hope I could help,
Narusan

Pyinstaller with Tkinter Matplotlib numpy scipy

I am using Pyinstaller (after spending a long time with py2exe) to convert my REAL.py file to .exe. I used Anaconda to make .py file which is running perfectly on my computer. But when I make .exe file, it shows no error and an application is created in dist\REAL folder. But when I run the .exe file, the console opens and closes instantly.
It should ideally show a GUI window and take inputs and use them to make plots. It does so when I run REAL.py file. I am using Tkinter, Matplotlib, numpy, scipy which comes with Anaconda.
EDIT: I tried to run simple code to check the compatibility with matplotlib:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
The same issue persists with this. Opens console window and then closes but no plot is given out.
I found the solution in py2exe. Following was the setup.py file that worked with Tkinter Matplotlib numpy scipy imports:
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import matplotlib
opts = {"py2exe": {
"packages" : ['matplotlib'],
"includes": ['scipy', 'scipy.integrate', 'scipy.special.*','scipy.linalg.*'],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll']
}
}
setup(
windows = [{'script': "with_GUI.py"}], zipfile = None,
options= opts,
data_files = matplotlib.get_py2exe_datafiles()
)
But this gave me some error saying that there was version conflict with two files. So I changed the two files viz. dist/tcl/tcl8.5/init.tcl (in line 19) and dist/tcl/tk8.5/tk.tcl (in line 18). In my case I changed the version from 8.5.15 to 8.5.18. I found the location of the two files by looking at the path specified by the error in error log. Then the .exe worked just fine.
I hope this helps.
Try using the --hidden-import=matplotlib when calling pyinstaller. For example, in the command prompt you would type:
Pyinstaller --hidden-import=matplotlib your_filename_here.py
and you could try giving it a shot with tkinter in there as well.
Pyinstaller --hidden-import=matplotlib --hidden-import=tkinter your_filename_here.py

Matplotlib Basemap Installation Troubles on OS X Yosemite

I've been having very serious issues installing Basemap from mpl_toolkits. Fortunately, it looks like I'm not the only one having these issues... I was wondering if someone could help me here.
I'm currently running OS X 10.10 (Yosemite).
Long story short, I was able to install Basemap via Anaconda after much difficulties. Now whenever I try to import Basemap, I get the following error:
28 from matplotlib.lines import Line2D
29 from matplotlib.transforms import Bbox
---> 30 from mpl_toolkits.basemap import pyproj
31 from mpl_toolkits.axes_grid1 import make_axes_locatable
32 from matplotlib.image import imread
ImportError: cannot import name pyproj
...which doesn't make sense to me at all. I have pyproj installed, and I physically see it in my Anaconda pkgs folder. It's called pyproj-1.9.3-0. I also have basemap-1.0.7-np19py27_0 in my pkgs folder.
Does anyone have any idea what's going on? Maybe I stupidly forgot to do something? Sorry if it's a dumb question - I'm an amateur when it comes to these sorts of things.
I just managed to install Basemap on Yosemite with Anaconda without any problems, so maybe there's something unusual about your set-up (what issues are you refering to?)
What I did was simply
conda install Basemap
But here are some things to think about:
Did you install anything after issuing this command (on my system, conda updated my matplotlib to 1.4.3 as part of this installation. You could try conda update, but you might need to do some fixing if you changed anything "by hand".
Are you using the right virtual environment (the one from which you installed Basemap)?
import Basemap with from mpl_toolkits.basemap import Basemap rather than the import Basemap that your question implies: see e.g. this example.
type which python and check that the output is along the lines of
/Users/<username>/anaconda/bin/python
or
/Users/<username>/anaconda/envs/<virtual-env>/bin/python
and that you're not using your Mac's system Python which would be something like
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python