How does one successfully download AND import pygame? - python

the problem:
as part of my studies, i have tried to download PyGame for my own independent project. I've currently downloaded 1.9.6, as well as currently owning IDLE version 3.8. i have imported it many times:
folder.
on one occasion , i placed it in its own separate folder with the coding file in another internal folder
when importing it into a new python script, the result was that there was "no module named Pygame", even though it was in a file containing the recent edition (this method was used successfully to download Tkinter).
I also tried making a python script outside the contained folder like this
this,too had the same result.
Any idea what exactly to do?
any more important information
The computer type is a MAC 10.13.6 and the IDE is IDLE. As previously mentioned, the downloaded version is version 1.9.6 and i have not a clue what how many bits my computer manages. Apologies that this is probably one of MILLIONS of the exact same question answered.I've tried at least 2 of these solutions.

First you need to make sure that you have pip installed. Type pip in your cmd (command prompt) and if you get no errors you are fine. If you have errors follow this link to get it. If you are stuck on that link - basically all you need to do is uninstall python and then when you are installing it again tick the box that says:
Add Python 3.5 to PATH
Now just finish installing python.
Next you need to install pygame with pip install pygame in your cmd - run it as administrator just to be safe. If you receive errors try updating pip with python -m pip install --upgrade pip. Now create and save a new python file. Import pygame in that file by using the code import pygame. The output should be:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Now you are free to code in pygame! I hope this helped.

Related

Problems with importing external module

I tried to download an external module to test how it works, by simply downloading 'Simplejson' using pip in cmd(Window). I watched my teacher did it, and followed it the exact way but i ran into a problem.
Not sure what i did, because my teacher just told me to follow him, i think we created a virtual environment on python so that we can do more than one projects with various versions of python. Anyway, most of you will know that after creating a virtual environment in my folder that i work for coding, a 3 new folders will appear and 'Simplejson' will be inside Lib\site-packages. Even if i checked that Simplejson is still inside the file, some how i can not import it. Are there any way that i can solve it?
enter image description here
Please refer to the following to check the process of installing and using the module "Simplejson" in VS Code:
Please check whether the python currently used by the VS Code terminal is the same as the one displayed in the lower left corner of the VS Code: (python --version or pip --version)
(If they use different pythons, please open a new VS Code terminal, it will automatically enter the selected environment.)
Then install the module "Simplejson".
Check the installed modules: (pip show Simplejson)
Run:
Reference: Python Environments in VS Code.

Python packages are imported on terminal but not on IDLE

So I am new in Python. I downloaded Anaconda (and Homebrew) and using Terminal on my Mac I confirmed that, say, Numpy is installed:
pip install numpy
to get as a result
Requirement already satisfied: numpy in ./anaconda/lib/python3.6/site-packages
Then opening Python within Terminal I can indeed import the package. The story is not the same once I open IDLE. So when I open it and try to import, say, Numpy I get the following message:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
I guess there is something I do not know, I assume it is a common rookie problem. Can you help me with this?
Since your IDLE is using Python 3 you should use
pip3 install numpy
to get it installed for the correct Python. If you want to use your default installed Python (2.x) instead, IDLE is located at /usr/bin/. From your terminal you can open it with
/usr/bin/idle
this should have the numpy you installed with pip install numpy
See when you are working with Anaconda it creates its own virtual environment.
Now, If you are new in python on MAC then you might not familiar with Virtual Environment.
I suggest you to download python from the official website www.python.org
or Click here to directly download Python 3.6.2 on your MAC.
Then, Download Pycharm(The Best IDE for Python)
Download the community version for beginner and it is also free.
Pycharm Community Version -> Click Here
And do whatever you want and also must read about Virtualenv
According to me, Pycharm is better then Anaconda's Jupyter Notebook
Wish you good luck and show your creativity in python ! !
Erm... well it appears as though - since you have 2 versions on your computer - that it might be because it imported it into the other file path directory. Now, I've never worked with Mac, but I think if you just specify which pip you want to download from, it might work.
For example, on Windows:
C:\Python34\Scripts\pip.exe install numpy
or if you were doing it for 3.6, you would follow the path to the folder, find pip and install. So, I suggest to install the normal IDLE before any other platform built upon it just because it is easier to import modules and is not as bad to break like yours has.
There can be two issues -
You are using python 2 as a kernel for IDLE, since numpy is installed for python3.6. This will raise an error.
The issue is with anaconda's configuration with IDLE. Anaconda installs numpy in ./anaconda/lib/python3.6/site-packages. If IDLE uses systems default python instead of anaconda's. You will not be able to import numpy.
You can try running this snippet -
import sys
print('\n'.join(sys.path))
to track the location of python exactly.
One of the workaround that I can think of is -
create a virtual environment using anaconda. Something like
conda create -n py352 python=3.5.2 anaconda
and then fire IDLE from your terminal. Though I am not entirely sure, if this works for mac. If it doesn't, let me know the output of -
import sys
print('\n'.join(sys.path))

Installing PyGame - ImportError: DLL load failed

My current version of Python is the newest 3.5 and the only available PyGame was for 3.2 (both PyGame and Python are 32-bit). I've scoured stackoverflow for a resolution and can't find any way to make this work. I've installed the PyGame easy installer and placed it in the directory where my Python install is, and in Visual Studio (I've also tried this in PyCharm as well as the standard Python IDE in command prompt), upon typing
import pygame or import sys, pygame
I'm presented with the error Import Error was
unhandled by user code - DLL load failed: The specified module could not be found.
My final solution is to uninstall Python 3.5 and install the version which matches PyGame.
This shouldn't have anything to do with Python version. You are missing a dynamic library (the DLL). This means that either the DLL is not on your system or Python can't find it. You should probably try the msi/exe installer for PyGame mentioned here, as it should install any dependencies. This would fix the issue if it is caused by the DLL being absent from your system.
It could also be caused by the libraries not being on PYTHONPATH. Search the error you received and you should see quite a few answers on fixing this.
If you're just getting started, you may want to look at a different library. There are likely quite a few game libraries for Python that can be installed with a simple pip install. You could then return to PyGame when you are more comfortable if you wanted.
get it from here: https://www.dropbox.com/s/hnmcaq1rf6zn7m3/pygame-1.9.2a0-cp34-none-win32.whl?dl=0
download it and install it by putting it in C:\python3.5\Scripts
then run pip3 install pygame-1.9.2a0-cp34-none-win32.whl
(this is for 3.4, but 3.5 works too)
it should work, and your error has nothing to do with the package, it's just that you do not have a DLL file, install it again from the website above

How to install apscheduler

I would like to use scheduler in my python program however I haven't been able to install it.
I tried with Easy_Install and PIP (neither of which I've used before) and I can't find a link for another method. I'm using Python 2.7 on Windows Vista
Since I've never used PIP before I had to install that first. After installing pip I went to command prompt, changed to the directory with pip and typed:
C:\Python27\Scripts>pip install apscheduler
It didn't come up with an error so I assumed it installed, however when I run my python program, which includes the line: from apscheduler.scheduler import Scheduler
it states:
ImportError: No module named apscheduler.scheduler
and when I look at the list of installed modules in Idle it's not there.
It's probably something obvious since I don't have a lot of experience in programming yet.
Help would be much appreciated!
sm
Hi again,
I got it working finally, in the end I didn't use PIP, in case other people need help this is what I did:
Downloaded the apscheduler tar.gz file
Downloaded 7-zip, since this can extract tar.gz files on Windows.
Extracted the tar.gz file using 7-zip, I had to do this twice since the first time I clicked extract it extracted to a .tar file (APScheduler-2.1.2.tar), it was necessary to extract this file as well.
Added C:python27\ to the windows path (this is in control panel->system & maintenance->system->advanced system settings->environment variables)
(I also added C:python27\scripts\ to the path, but not sure whether this makes a difference.
Opened command prompt and moved to the folder containing the extracted APScheduler files including the file named setup.py
In my case this was- C:\Python27\APScheduler\APScheduler-2.1.2\APScheduler-2.1.2\
In command prompt typed> python setup.py install
Hopefully this was everything, perhaps one day I'll delete everything and try again to check, but it took quite sometime to get it going so right now I think I'll leave it as is.

'Web' module cannot be found while having installed lpthw.web

I'm currently doing the exercise in "Learn python the hard way".
In this exercise i have to install the lpthw.web frame work.
Having installed pip in windows, i open my terminal and hit
pip install lpthw.web
Everything then ends succesfully.
But when i browse C:\Python27\Lib\site-packages\lpthw.web-1.1-py2.7.egg-info and check the installed-files text i can't see the web.py.
Consequently when i try to import it in a simple script i get ImportError.
I don't have python 3 installed as book suggested for possible cause, so i don't know how to work around it.
Any suggestion?
I checked my path
import sys
sys.path
and saw that every single line was using the panda3d path.
As i was not really using it, unistalling it fixed my problem.
For me it was python version control on raspberry pi
(linux) 2.7 is default and does not work.
follow:
https://learn.sparkfun.com/tutorials/python-programming-tutorial-getting-started-with-the-raspberry-pi/configure-your-pi
have other errors now but the import web loads in python.
cheers!

Categories