so i've recently installed pygame because i want to start programming with it. Before writing code, i decided to just make sure its running fine by testing it in IDLE.
i ran
import pygame
no error
i ran
pygame.init()
and got the following error
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
pygame.init()
AttributeError: module 'pygame' has no attribute 'init'
by doing some research i found out that it may be messing up the path, so i tried
pygame._path_
and got a similar error
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
pygame._path_
AttributeError: module 'pygame' has no attribute '_path_'
and i can't figure out whats wrong. i've tried solutions in other questions but nothing works
im using
Windows 10 Home
Python 3.5.2 32 Bit
Pygame 1.9.2a0 for python 3.2 (but after looking up if it would work with python 3.5, i found resources saying it would)
i tried installing the 3.5 version as a .whl but it had its own host of problems and just decided to use the installer. is the error because of the mismatch between python versions and pygame versions, or is there something else i can try?
I have tried the following
pygame._path_
there is nothing else named pygame.py that would confuse the path
i used the installer
i made sure there were no other versions of python/pygame installed
So are there any other solutions beyond the ones that i have tried to get this one working?
Thank you for your time.
EDIT 1: I have made sure that the only directory named pygame is the module.
to finding the pygame path:
Magic methods have two underscores on either side of them.
to the lack of pygame.init():
different software seem to be able to find different parts of pygame, because PyCharm cannot locate that function, but when running off the command line it operates perfectly. It may just be a fault of idle. Try running from the command line or double clicking the .py file, assuming it is associated with the interpreter. If that doesn't work, run the command
python -m pip install --upgrade pygame
Have you installed pygame correctly.
Put this in your cd (command prompt) to check if you have installed pygame properly
py -m pygame.examples.aliens
If it gives a error then you should use the pip install function
py -m pip install -U pygame --user
If everything fails you can install an IDE. I would recommend pycharm https://www.jetbrains.com/pycharm/download/#section=windows
It is a free IDE and you can install pygame from there for a project
File --> Settings --> Project:(Name) --> Project Interpreter --> pip --> type pygame and install package.
Pycharm pygame installation
Related
I have recently bought a new laptop and was viewing some python projects of mine which I made on my pc. For one of them I use the python-bitvavo-api library which I installed using pip3 install python-bitvavo-api. The version I installed is 1.2.2 which is the latest on their website.
Now when I try to import it using this code: from python_bitvavo_api.bitvavo import Bitvavo, I get the following error:
Traceback (most recent call last):
File "C:\Users\indig\OneDrive\Documenten\Python Projects\Personal\Cryptone\Cryptone.py", line 6, in <module>
from python_bitvavo_api.bitvavo import Bitvavo
ModuleNotFoundError: No module named 'python_bitvavo_api'
I read online that it may occur when using multiple python versions, Im only using 1 and thats python 3.7
Btw. I have the same error with the Pillow module, so it might be a setting in visual studio that I dont know of. Anyway, someone please help. If you need more details please ask.
How are you running it? From the terminal or from VS?
You can also check the installed libraries running the command pip list
I'm currently making a project that i'm using the python-vlc module for in order to play MP3 audio. Whenever I run the script that the I want the audio to play in.
I've tried a few things, reinstalling VLC to the latest 64-bit version, installing the 32-bit version, reinstalling the python-vlc module itself, upgrading python, but nothing has seemed to have worked.
Here's the code being ran that throws the issue:
import vlc
# Audio Variables
CC_INTRO = vlc.MediaPlayer("audio/CC_INTRO1.mp3")
Normally it should just run the code and be done with it, giving me the ability to call back on the "CC_INTRO" variable and then play the audio, but instead it gives me the error
>
Traceback (most recent call last):
File "weatherinfo.py", line 4, in
import vlc
ModuleNotFoundError: No module named 'vlc'
Does anyone know what's going on here? I can't seem to figure it out. Also, I'm using PyCharm, if that helps at all with figuring out the issue.
If it is ModuleNotFoundError then maybe vlc module itself is not installed for the version of python you are using. Make sure you install python-vlc for all versions of Python that you might have on your machine.
E.g. python3 -m pip install python-vlc
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 attempted to run the program that plays mastermind, here:
http://www.python-course.eu/mastermind.php
To do so, I installed python3.4.3 first.
I ran the program, but it returned:
Traceback (most recent call last):
File "mastermind_p1_trim.py", line 5, in <module>
from combinatorics import all_colours
ImportError: No module named 'combinatorics'
So I navigated to https://pypi.python.org/pypi/Combinatorics
and downloaded it, then ran python3
python3 setup.py install
from within the Directory downloaded.
This returned
Writing /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/Combinatorics-1.4.5-py3.4.egg-info
finally, sys.path returns
['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
when running python3.
So, I do not know why I am still receiving the error,
ImportError: No module named 'combinatorics'
I have looked at other similar pages on SO, but the suggestions there do not seems to solve my problem. Could anyone help me figure this out?
Combinatorics might not be compatible with Python 3.4.3
Here are some suggestions:
Un-install Python 3.4.3 and all it's resources
Install python 2.7
Install combinatorics
Read more in detail
Here is a guide from ActiveState:
Download and install ActivePython
[IGNORE THIS] Buy and install the Business Edition license from account.activestate.com
Open Command Prompt
Type pypm install combinatorics
I'm using Ubuntu 12.04 and installed python-nmap to create a script. If I use IDLE and type in the following, it runs fine:
import nmap
nm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')
However, if I perform this in Eclipse, I receive the following error:
Traceback (most recent call last):
File "/home/russ/workspace/ViPyNmap/MyFiles/nmaptest.py", line 2, in <module>
nm = nmap.PortScanner()
AttributeError: 'module' object has no attribute 'PortScanner'
I've added the egg file and also the folder to the Eclipse path for the project, with no luck. I've also restarted Eclipse after doing so, with no luck. I apologize for my inexperience with both Eclipse and Python and appreciate the help.
You likely installed the package "nmap", not "python-nmap":
So, just uninstall "nmap" and install "python-nmap":
pip uninstall nmap
pip install python-nmap
1 analyzing
If you see the source code nmap.py at directory /usr/local/lib/python2.7/dist-packages/nmap/, you will find that there is not class PortScanner.
2 solution
2.1 method one
You should delete the directory .../nmap/ with contained files, and install the new the packages nmap or bypython setup.py install at new packages directory.
2.2 method two
You also can copy the file nmap.py at the new packages to your directory .../MyFiles/ with your py file nmaptest.py, and run your command python nmaptest.py.
good luck for you !
The reason why this is happening is because your module that you named nmap.py is now shadowing the intended requests module you are trying to use.
To avoid this, you should rename your module to something else to avoid these situations. Furthermore, chances are you will have generated a nmap.pyc file as well, local to where your nmap.py resides. Make sure you remove that as well after your rename, as the interpreter will still reference that file, re-producing the error.
Example of problem resolution:
renaming file to nmapscan.py, removing nmap.pyc and running again.
Well above answers are working fine in python 2.7, but when we are working in python3 environment following will help to resolve it
pip uninstall nmap
pip uninstall python-nmap
pip3 install python-nmap