I was trying to get pygame on my mac to work. I got it running in terminal. But I run into issues when trying to use it with netbeans or trying to run the file. It gives me the error
from pygame.locals import *
ImportError: No module named locals
any help? Thanks!
If you still want to use netbeans, I think you should take a look at ActivePython
Activepython basically lets you install different pythons on your machine and be able to select between them (there's a lot more features I'm sure).
My advice would be to go to the console and type
>python
>>> from pygame.locals import *
If that works, ctrl-c out and do a python -v to find out the version.
Once you have the version, you can use activepython to select that version by running:
sudo pysel [version]. For instance for python2.7:
sudo pysel 2.7
This should switch the python over and your netbeans should (hopefully) work with it.
Related
this might be a very stupid question but I'm a beginner.
I want to use this package called colorgram, it's a module that extracts colours from images, and I installed it using pip via the CMD. but when I try to import it in VS code it can't find it and I don't know what to do, please help
#Andrii Zadaianchuk
sorry, I'm using windows 10. I tried to import it in python in the CMD but nothing either, just the same ModuleNotFoundError: No module named 'colorgram' error.
I did just notice that the modules python version is 3.5 and VS code is running 3.9.2. I think that might be the problem
I'm more specifically wanting to know whether sqlite3 and json comes with python IDLE or do I have to install them separately to use them inside IDLE, If so can anyone link me to those installing procedures of sqlite3 and json on Python IDLE?
I also want to know where I can find the list of other pre-installed packages that comes with basic Python IDLE (i.e. Python 2.7.14) . I am a Beginner and it would be really helpful.
Thank you.
To get a list of your packages, from your terminal, launch python :
python
Then
help("modules")
Another solution, if you want to check if json or sqlite3 are installed, start Python from your terminal :
python
Then import sqlite3 and json:
import json
import sqlite3
You can check theirs version with :
>>> json.__version__
'2.0.9'
>>> sqlite3.version
'2.6.0'
IDLE is part of the CPython standard library and is usually installed when tkinter (and turtle) are. It provides an optional alternate interface for running your code with a particular python binary. When you run code through IDLE, it is run by the python binary that is running IDLE. So the same modules are available whether you run code through the terminal interface or through IDLE. There is no separate installation.
I installed Pygame on my mac using Anaconda.
pip install pygame
>>>Requirement already satisfied: pygame in /anaconda/lib/python3.6/site-packages
The thing is, I do not know to use it now. When I run a simple file from my code editor it says:
File "/Users/julien/untitled5.py", line 1, in <module>
import pygame
ImportError: No module named pygame
any advice ? I tried to run pygame using spyder from the Ananconda Navigator bun it does not seem to work either.
The issue is that your IDE is looking in the wrong places for pygame. To see where it's looking for packages, run this script in the console for that IDE:
>>>import sys
>>>sys.path
This will show a list of paths where python looks for packages. /anaconda/lib/python3.6/site-packages won't be there, which is why you can't import it. What IDE are you using? Most are able to change their settings so that they can import from different places, see if you can do that, and put /anaconda/lib/python3.6/site-packages as part of the path.
I am fairly new to python but am having issues importing certain packages within my code. I try to import pyperclip aswell as pygame. I've installed them both manually and I've tried importing them using import pygame and import pyperclip and I get
"no module named 'pyperclip'"
and the same thing for pygame. I've tried opening by putting just import pygame and saved it to run it in the interactive shell and I've also just tried typing it into the interactive shell.
I'm running linux mint 17.3 and python 2.7.6
Has anyone else had this issue?
Any help would be appreciated. Za
I had the same problem. I am also new to Python and programming. I tried about 100 things, but what worked for me was typing the following in the command shell:
pip install pyperclip
That was it. However, I was using Windows' command module, so. . . you know. But it's worth a shot!
This link might help, too (it has Linux instructions, etc): https://github.com/asweigart/pyperclip
I'm working on learning to make GUIs with Tkinter for Python programs and I have run into a bunch of problems:
Attempting to run from Tkinter import filedialog I get ImportError: cannot import name filedialog. Elsewhere I have seen it called with the lowercase tkinter (which I think is for Python 3 only) but it does not recognize that as existing ImportError: No module named tkinter. Yet running from Tkinter import * works and I'm able to create the sample hello world from the tutorial.
My only guess is that it is attempting to use an obsolete version of Tkinter that shipped with OSX. Yet considering how new Mountain Lion is, I have to wonder how obsolete it would really be. My assumption is that upon installing Python 2.7 myself, if I run from IDLE, it should work, but instead I get exactly the same thing above from the IDLE shell.
So after that I tried sudo pip install tkinter and sudo pip install Tkinter from the Unix terminal, but I get back No distributions at all found for update
So I start looking into documentation on Tkinter itself, and I come across Tcl/Tk instructions for Mac OS X which states:
Important: If you are using Mac OS X 10.8, 10.7 or 10.6, use IDLE or tkinter from a 64-bit/32-bit Python installer only with ActiveTcl 8.5 installed. If you cannot install ActiveTcl 8.5, use a 32-bit-only installer instead.
So I find my OS in the table they provide and see that they recommend ActiveTcl8.5.11, but unfortunately, the download link is broken.
So I'm completely at a loss here. Any help would be appreciated.
If you want to implement a File Dialog, have a look at tkFileDialog. It is a seperate module & not part of Tkinter module.
You can use it by directly importing it:
import tkFileDialog