redis-py AttributeError: 'module' object has no attribute - python

I installed redis-py on CentOS and Ubuntu. On both I get the same error when trying to access it.
redis-py AttributeError: 'module' object has no attribute
If I use the python prompt in the same directory as the source this will work:
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
but if I change directories it will give the error.
>>> import redis
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "redis.py", line 4, in <module>
print redis.__version__
AttributeError: 'module' object has no attribute '__version__'
Trying with a .py script always gives the error. Any idea what I'm doing wrong, and how to fix it. Probably a newbie Python thing...

You're naming a module you're working on redis.py and Python is importing that instead of the real redis module. Don't do that, or change sys.path to make sure the current working directory is last rather than first in the lists of directories to search.

i have this error in tornado and it was because i install redis on python 2.7 and install in python3 too , i uninstall redis from python2.7 and re_install in python3 and solve the Problem!

Related

Python 3.9.5 has attribute error in datetime.datetime.now(). how to solve it?

Traceback (most recent call last):
File "E:\whitedark\Python\Xample\datetime.py", line 1, in <module>
import datetime
File "E:\whitedark\Python\Xample\datetime.py", line 3, in <module>
todate = datetime.datetime.now()
AttributeError: partially initialized module 'datetime' has no attribute 'now' (most like
ly due to a circular import)
My code is simple. Just ...
import datetime
todate = datetime.datetime.now()
print(todate)
That is all. In the example they show, it works. I use Thonny. The code can run perfectly inside Thonny which use python 3.7.9. I don't use F5 to run code. The shell blocks half of my code. I can't see all. So, I use cmd which uses python 3.9.5. Should I uninstall python 3.9.5 and install 3.7.9? or is there another way? I think the higher version is better. Not? or did they remove 'now' attribute in 3.9.5? if so, is there any better site to learn python?

Issue importing PyVISA

On Windows 8, Python 2.7, and PyVISA 1.4:
I have tried multiple installs, most recently using easy_install.
When I enter import visa, it seems to work, and I do not get an error message.
When I try to run 'lib = visa.VisaLibrary()', I get the following error returned:
>>> lib = visa.VisaLibrary()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'VisaLibrary'
>>>
I clearly have some functionality, as the resource manager exists:
>>> rm = visa.ResourceManager()
>>> print(rm)
ResourceManager()
So, why does it seem like I do not have access to all VISA functionality?
VisaLibrary is a function introduced in version 1.5. For 1.4, you have visa_library.
To make sure everything is correct, you could run the tests; usually pyvisa.test().

AttributeError: 'module' object has no attribute 'Api'

I have written some basic Python code to try authenticate my credentials on twitter:
import twitter
api = twitter.Api(consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
But I receive the following error message when doing so:
Traceback (most recent call last):
File "C:\Python33\nettest.py", line 3, in <module>
api = twitter.Api(consumer_key='',
AttributeError: 'module' object has no attribute 'Api'
Can anyone see what I am doing wrong? I have tried variations on this code but they all seem to fall down with the api part of the twitter 1.14.2 that i am using. i have installed this module via pip 3.3 to my python 3.3 directory. when i look in lib>site_packages>twitter i can see that there is a module installed called api. I'm really not sure what is going wrong as this should seemingly be a simple piece of code to run.
Any ideas?
simply uninstall twitter sudo pip uninstall twitter
Now install python-twiiter sudo pip install python-twitter... and it works..
If you were using the python-twitter You have a local file named twitter.py Rename it to twitterhelper.py or some other name and it should fix your problem. This was what fixed it for me.
Save your python file with any name other than twitter.py.

Trying to run pyexiv2

I'm trying to run a simple code to test that I have installed correctly pyexiv2 in my computer. I'm using python 2.6.6. on windows 7 64 bit
So I run this simple code:
import pyexiv2
print pyexiv2.exiv2_version_info
and I get this error:
Traceback (most recent call last):
File "C:/Users/Usuario/Desktop/pyexiv2/pyexiv2.py", line 1, in <module>
import pyexiv2
File "C:\Users\Usuario\Desktop\pyexiv2\pyexiv2.py", line 3, in <module>
print pyexiv2.version_info
AttributeError: 'module' object has no attribute 'version_info'
How can I fix that? Thank you
You named your own file pyexiv2.py as well; rename it or delete it, as it is being imported instead of the installed module.

Pycurl Error : AttributeError: 'module' object has no attribute 'Curl'

Brand new raspberry pi using the debian image from the pi site.
I used sudo apt-get install python-pycurl
My script looks like this
import pycurl
c = pycurl.Curl()
c.setopt(c.POST, 1)
c.setopt(c.SSL_VERIFYPEER, 1)
c.setopt(c.CAINFO, '/etc/ssl/certs/ca-certificates.crt')
c.setopt(c.URL, 'https://theurl.com')
c.setopt(c.USERPWD, 'user:pass')
c.setopt(c.POSTFIELDS, 'Field1=This&Field2=That')
c.perform()
I'm getting this
Traceback (most recent call last):
File "pycurl.py", line 1, in <module>
import pycurl
File "/home/pi/test/pycurl.py", line 3, in <module>
c = pycurl.Curl()
AttributeError: 'module' object has no attribute 'Curl'
Look at the path in the traceback. It looks like you may be importing your own module called pycurl.py, not the actual pycurl library. Try renaming that file to something else so Python imports the real pycurl.
python first checks in the current directory for a module, then in the python directory.
rename your file to mypicurl.py or something. otherwise, you're just importing the script.
edit: i just saw your comment, and this means you havn't installed it properly. try a reinstall or install from a .deb

Categories