AttributeError: 'module' object has no attribute 'MCA' - python

I want to do correspondence analysis for the categorical features in my dataset but get this error.
import mca
mca_counts = mca.MCA(test.drop('ID', axis=1))
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
mca_counts = mca.MCA(test.drop('ID', axis=1))
AttributeError: 'module' object has no attribute 'MCA'

Apparently, the latest version of the library in PyPI is 1.0, where the class is called mca.mca. It was renamed to mca.MCA only in 1.0.1, but that version for some reason has never made it to PyPI. Consider either using mca.mca, or reinstalling it from git, or finding something less abandoned.

Related

AttributeError: 'DataFrame' object has no attribute 'items' (pandas DataFrame error)

I've created a pandas DataFrame with data from loops (data saved here). Now, I want to iterate over this DataFrame. However, when I try to access the items() function like this:
frame = pandas.read_csv(data_path + '/file1.csv')
frame.items()
I get this error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\ArcGIS10.7\lib\site-packages\pandas\core\generic.py", line 2668, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'items'
This is especially weird since PyCharm offers me the option to fill in items if I just type frame.it
What does this mean?
Check your pycharm interpreter. Normally the attribute 'items' works well in Python 3.x but gives the error "AttributeError: 'DataFrame' object has no attribute 'items'" in Python 2.7.
I also faced the same error until I realized that I was using Python 2.7 instead of Python 3.9 that I intended to use.

Keras strange crash

Training model in Keras I get exception at some epoch:
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f036d74b7f0>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 686, in __del__
TypeError: 'NoneType' object is not callable
What could be reason of such behaviour?
This might be caused by the Cache file, you can try deleting the pycache folder. This works for me.
I am using the Tensorflow version.

Python's mock throwing AttributeError: 'module' object has no attribute 'patch'

I am trying to create some tests for a Python program. I am using Python version 2.7.12 so I had to install mock using sudo pip install mock.
According to the documentation and several other sites, I should be able to use the following code to use patch:
import mock # Also could use from mock import patch
import unittest
class TestCases(unittest.TestCase):
#mock.patch('MyClass.ImportedClass') # If using from mock import patch should just be #patch
def test_patches(self, mock_ImportedClass):
# Test code...
However, the above code throws the following error:
AttributeError: 'module' object has no attribute 'patch'
After some experimenting in the terminal, it seems quite a few things don't work. For example
>>> import mock
>>> mock.MagicMock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MagicMock'
>>> mock.patch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'patch'
>>> mock.Mock
<class mock.Mock at 0x7fdff56b0600>
Interestingly, I can access something called patch using mock.Mock(), but I don't know if this works in the same way and cannot find anything about it in the documentation.
My experience with Python is fairly limited so I'm not sure what might be wrong. I'm fairly certain the right package was installed. Any help on how I can get this working?
Just for the sake of completeness, I wanted to add the answer, but the credit goes to #user2357112.
If you run into this issue check to make sure you don't have another file named mock.py (or whatever file you're trying to import) either in the same directory or in the search path for python. To confirm you've loaded the correct file, you can check mock.__file_, which is an attribute added automatically by python to your imported files. If you're using the terminal, you can just do something like:
>>> import mock
>>> mock.__file__
'/usr/lib/python2.7/...'
If the file path doesn't match what you expect, you should remove the file being imported from your search path or modify your search path so that the file you want is found first. If neither of those are an option, you need to change the name of the file you're importing (if it's one you define and not a library like mock).

Why does the following attribute error occur?

I get the following error when trying to execute the following in Python with the PuLP library
for i in range(0, items):
print('x{0} = {1}'.format(i+1, value('x{0}'.format(i+1))))
That is my code which throws the following error
Traceback (most recent call last):
File "C:/Python34/knapsack.py", line 81, in <module>
print('x{0} = {1}'.format(i+1, value('x{0}'.format(i+1))))
File "C:\Python34\lib\site-packages\pulp-1.6.1-py3.4.egg\pulp\pulp.py", line 1990, in value
else: return x.value()
AttributeError: 'str' object has no attribute 'value'
My question is why does this not work. Splitting the print statement tends to work correctly.
The value method expects a PuLP variable object, not a string with the same name as one.
In order to evaluate your string back to a python variable, you need to eval it, so that would look like.
value(eval('x{0}'.format(i+1)))

AttributeError, why?

I'm writing a program that solves a tetravex and I encountered this error:
AttributeError: 'list' object has no attribute 'PlacementList'.
I tried everything I know but don't know why I'm getting that error. Could you please tell me what I did wrong?
This is a pastebin link to my code: http://pastebin.com/d1WdbCUu
It happens when you are trying to get PlacementList attribute of a list, obviously.
Here is the example:
>>> a = []
>>> a.PlacementList
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
a.PlacementList
AttributeError: 'list' object has no attribute 'PlacementList'
Just find the code where something similar happens - you are trying to get PlacementList attribute of the object that can be of type list.

Categories