What am I doing wrong when trying to use easygui.enterbox(...)? - python

I am three weeks into my independent study Python course, and am having trouble getting passed an issue. I am trying to use the function enterbox() from easygui I write:
import easygui
value = easygui.enterbox("say something")
And when I run it I get the error:
**AttributeError: 'module' object has no attribute 'enterbox'
Does anyone know why this may be happening? Thanks! (I'm using version 2.7)

Related

Getting attribute error on attribute being imported

Sorry for all the questions and thank you for the help.
I have the following code that I'm working for school. I'm trying to import the Cerberus package into my code with "import cerberus" and that works with no problems. However, when I run the code I get the following message "AttributeError: 'module' object has no attribute 'Validator'" Looking over the documentation on Cerberus, it appears I'm doing calling the right things with "import cerberus" and "validator = cerberus.Validator()" or "validator = cerberus.Validate()"
Can someone explain to me what I'm doing wrong? I've been bashing my head for weeks on this problem. Thanks for the assistance, it's greatly appreciated.
import cerberus
validator = cerberus.Validator()

'module' object has no attribute 'cmap' in cubehelix python

I'm trying to use cubehelix in python however I've been getting simple problems which I don't think should be showing up. The code I'm using is the following:
import matplotlib.pyplot as plt
import numpy as np
import cubehelix
cx1 = cubehelix.cmap(reverse=True)
alplot = plt.imshow(rtotal_rotated,vmax=1100,extent[-21,19,23,-17],cmap=cx1)
However the following error comes up when I run the code:
AttributeError: 'module' object has no attribute 'cmap'
I know this can't be right since I'm simply following the code from this tutorial
http://www.ifweassume.com/2014/04/cubehelix-colormap-for-python.html
So I'm not sure why it's breaking.
Very like that the script imports itself, i.e. your script is named cubehelix.py. So, if you have file named cubehelix.py in your current working directory, rename it to my_cubehelix.py and try again.

Trouble remembering import rules in Python

It's been a while since I have used Python and am stumbling already at a simple import!
statements.py:
str = "hello"
main.py:
import statements
print statements.str
Obviously the final program will have more going on, and the statements will be stuff like URLs. For this simple example however with both files sitting side by side in the same folder I get the following error on running main.py:
AttributeError: 'module' object has no attribute 'str'
I know I am doing something terribly silly, but I can't see what it is. Searching around it looks fine. Any help/insight is appreciated.
You used the import statement correctly. The error then can be caused by either importing a different module with the same name, or by having altered the module after already having imported it.
You can check print statements.__file__ to see what module Python found instead when importing, and you can use the reload() function to ask Python to reload the module from disk if you altered it.

Django XMMS2: 'module' object has no attribute 'XMMS'

I just started to use Python so the following might be a really REALLY dumb question but I searched the web for a long time and didn't find anything.
I'm trying to use the XMMS2 client from a Django View. Here is what I have in my views.py:
import xmmsclient
import os
import sys
def list(request):
xmms = xmmsclient.XMMS("tutorial1")
xmms.connect(os.getenv("XMMS_PATH"))
result = xmms.playlist_list_entries()
result.wait()
...
And here is the error I get:
AttributeError at /xmms2/list/
'module' object has no attribute 'XMMS'
And the line in question is this:
xmms = xmmsclient.XMMS("tutorial1")
The view works fine if I remove all the code and replace it with (for example):
return HttpResponse("list")
I first thought there was a problem with the xmmsclient library but it works fine when I run this xmms2-tutorial example
So I guess there is some sort of incompatibility between Django and xmmsclient but I really don't have a clue.
I'm running Ubuntu 12.04, Python 2.7.3, Django 1.4.1 and XMMS2 0.8
Any help will be really appreciated!
The problem was a name conflict. My Django app name was "xmmsclient".
So when I did
xmmsclient.XMMS("tut1")
I was referring to my app module, not the one from the XMMS2 client library.
Thanks a lot to Erik Massop from the xmms2-devel list!

Python AttributeError

When I type this code into a python shell it works perfectly fine but within a program it gives an error.
import os
h = os.environ['HOME']
within a script it gives this error:
AttributeError: 'str' object has no attribute 'environ'
Why is this happening and is there any way I can fix it?
(I'm kinda just learning python so I dont know much. Google didn't help)
Somewhere, you've created a string and named it os. The . is the attribute lookup operator, so it's complaining about the thing to the left of the ., in this case, os.
are you sure that between import os and h = os.environ['HOME'] you did not use os as a variable for a string?
edit: If you do not work with an editor with a debugger (e.g. Eclipse with PyDev), try to find out from which point os is no longer a module by calling print(os) at some key points in your code

Categories

Resources