AttributeError: 'module' object has no attribute
You have mutual top-level imports, which is almost always a bad idea.
If you really must have mutual imports in Python, the way to do it is to import them within a function:
# In b.py:
def cause_a_to_do_something():
import a
a.do_something()
Now a.py can safely do import b
without causing problems.
(At first glance it might appear that cause_a_to_do_something()
would be hugely inefficient because it does an import
every time you call it, but in fact the import work only gets done the first time. The second and subsequent times you import a module, it's a quick operation.)
Python AttributeError: 'module' object has no attribute 'Serial'
You're importing the module, not the class. So, you must write:
from serial import Serial
You need to install serial
module correctly: pip install pyserial
.
AttributeError: 'module' object has no attribute 'xxxx'
When you import foo, you just imported the package, not any of the modules, so when you called bar, it looked in the init.py file for bar, and that file doesn't have bar in it. If you don't import bar into the modules global namespace, it has no idea what bar is, which is why you got an error.
import foo
print(dir(foo)) # ['__builtins__', ...,'__spec__', 'print_message']
from foo import bar
print(dir(foo)) # ['__builtins__',..., 'bar', 'print_message']
You could add from . import bar
to the init.py file. This would make foo aware of bar when it runs the init.py file on import.
https://docs.python.org/3/tutorial/modules.html has some information about modules and packages, and there's some really good info in this post here Importing packages in Python
AttributeError: 'module' object has no attribute 'tests'
I finally figured it out working on another problem. The problem was that my test couldn't find an import.
It looks like you get the above error if your test fails to import. This makes sense because the test suite can't import a broken test. At least I think this is what is going on because I fixed the import within my test file and sure enough it started working.
To validate your test case just try import the test case file in python console.
Example:
from project.apps.app1.tests import *
AttributeError: 'module' object has no attribute 'ensure_str'
It looks like ensure_str was added to six in their 1.12.0 version, and that should be pooled in via apitools.
I suspect the root cause is that you have an older version of six (1.11 or older) installed in your virtualenvironment. Can you try creating a new virtualenv before trying your pipeline again, or running the quick-start example?
Related Topics
Unicodedecodeerror: 'Utf8' Codec Can't Decode Byte 0Xa5 in Position 0: Invalid Start Byte
How to Save a New Sheet in an Existing Excel File, Using Pandas
Python Re.Sub Group: Number After \Number
Pythonic Way to Check If a List Is Sorted or Not
Pandas Dataframe to List of Lists
What Exactly Does "Import *" Import
Rewrite Multiple Lines in the Console
Importerror: No Module Named 'Encodings'
Working with an Access Database in Python on Non-Windows Platform (Linux or MAC)
String Replace Doesn't Appear to Be Working
Why Does the Print Function Return None
How to Install Packages Using Pip According to the Requirements.Txt File from a Local Directory
How to Delete Items from a Dictionary While Iterating Over It
What Is the Standard Way to Add N Seconds to Datetime.Time in Python
Saving a Numpy Array as an Image
Convert Datetime Object to a String of Date Only in Python
How to Select Rows in a Dataframe Between Two Values, in Python Pandas