I have a file, A.py, it basically looks like this:
import Hasher
hh = Hasher.V2.Cached_V2()
When running, I get the error:
Traceback (most recent call last):
File "./A.py", line 2, in <module>
hh = Hasher.V2.Cached_V2()
AttributeError: 'module' object has no attribute 'V2'
On disk, the files layout is like this:
/A.py
/Hasher/__init__.py
/Hasher/V2.py
V2.py contains multiple classes, among them Cached_V2.
What's going on? Why isn't the object visible as expected?
In your A.py, use from Hasher import V2 Basically, when you are just importing 'Hasher' only the init.py file gets loaded.
Reference: Python error: AttributeError: 'module' object has no attribute
Note: In your Hasher/__init__.py file, if you import V2 using from . import V2, then you can use it by directly calling Hasher.V2 from A.py
Related
I am having troubles with making my code running in Python3 (it was in Python2 and I am converting it).
Here is the project structure:
lyrics/__init__.py
lyrics/lyrics.py
./manifold.py
in manifold.py :
import lyrics as lyr
lyr.Domain(label="Points", data=X)
where Domain class is defined in lyrics/lyrics.py:
class Domain(object):
...
When I execute manifold.py with:
./manifold.py
I get this error:
Traceback (most recent call last): File "./manifold.py", line 76, in
Points = lyr.Domain(label="Points", data=X) AttributeError: module 'lyrics' has no attribute 'Domain'
Any idea ?
Thank you
[EDIT]
in lyrics/init.py
from lyrics import *
from . import functions
I am running Windows 10 with MS Code Python 3.7
I get the following message from my simple code block
Traceback (most recent call last):
File "c:/Users/marke/OneDrive/Desktop/Python Tutorial/json.py", line 1, in
module
import json File "c:\Users\marke\OneDrive\Desktop\Python Tutorial\json.py", line 6, in
jsText = json.loads(FileText) AttributeError: partially initialized module 'json' has no attribute 'loads' (most likely due to
a circular import)
My code
import json
jsFile = open("myjson.json","r")
FileText = jsFile.read
jsText = json.loads(FileText)
When you name your script the name of the module you try to import, python tries to imports your script first, which results in the Error
I am trying to input a matix using numpy and I get the following error:
Traceback (most recent call last):
File "phase1.py", line 1, in <module>
import numpy as np
File "/home/rockstar/phase1.py", line 2, in <module>
a= np.array([1,2,3])
AttributeError: 'module' object has no attribute 'array'
I am not sure why this error is there. Could anyone help?
You probably have a file called numpy.py in the same folder that shadows the real numpy module. Rename your .py file and delete its .pyc file.
I trying create a script to find a exist folder, if not create this folder.
But when a call find from plone.api the output is AttributeError: 'module' object has no attribute 'find'
Bellow my terminal:
$ bin/instance -O intranet debug
>>> from plone import api
>>> from zope.site.hooks import setSite
>>> portal = app['intranet']
>>> setSite(portal)
>>> folders = api.content.find(context=portal, portal_catalog='Folder')
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'find'
>>>
What is wrong in my case?
I used this documentation plone.api.content.find
Need update plone.api to a version with support to method find. Like said by #LucaFabbri. In my case the product was update to 1.5.0.
i am learning python boto module and i am trying to stop a running instance .
import boto.ec2
conn = boto.ec2.connect_to_region("us-west-2")
conn.stop_instances(instance_ids=['i-0aa5ce441ef7e0e2a'])
but i am getting error which says:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'stop_instances'
i gave AWS_access keys for boto.
can anyone please help me to fix this error ?
As #kindall points out, your conn object is not initialized (it's NoneType). I also see that you're using boto in the example, but I thought that I would provide an example of this using boto3:
import boto3
boto3_session = boto3.Session(profile=some_profile_you_configured)
boto3_client = boto3_session.client('ec2', region_name='us-west-2')
response = boto3_client.stop_instances(InstanceIds=['i-0aa5ce441ef7e0e2a'])