Suddenly I cannot load some updated modules in Python

Suddenly I can’t load the updated module modules, for example scikit-learn, zope, but I can find other packages. Although the path links from the import point point to the correct anaconda folder containing all the code. Any ideas what could be wrong and how to fix it?

Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 >>> import sklearn >>> from os import listdir >>> print(dir(sklearn)) ['_ASSUME_FINITE', '__SKLEARN_SETUP__', '__all__', '__builtins__', '__check_build', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', '_contextmanager', 'base', 'clone', 'config_context', 'exceptions', 'externals', 'get_config', 'logger', 'logging', 'os', 're', 'set_config', 'setup_module', 'sys', 'utils', 'warnings'] >>> print(listdir(sklearn.__path__[0])) ['exceptions.py', 'cross_validation.pyc', 'lda.py', 'naive_bayes.pyc', 'isotonic.py', '_build_utils', 'neighbors', 'cluster', 'naive_bayes.py', '__init__.pyc', 'multiclass.py', 'dummy.pyc', 'grid_search.pyc', 'tests', '__init__.py', 'calibration.py', '_isotonic.so', 'neural_network', 'datasets', 'preprocessing', '__check_build', 'random_projection.py', 'multiclass.pyc', 'model_selection', 'calibration.pyc', 'pipeline.pyc', 'qda.py', 'learning_curve.py', 'ensemble', 'tree', 'isotonic.pyc', 'kernel_ridge.py', 'gaussian_process', 'decomposition', 'base.pyc', 'dummy.py', 'utils', 'pipeline.py', 'cross_decomposition', 'covariance', 'qda.pyc', 'multioutput.pyc', 'lda.pyc', 'feature_selection', 'linear_model', 'metrics', 'kernel_ridge.pyc', 'setup.py', 'semi_supervised', 'exceptions.pyc', 'multioutput.py', 'cross_validation.py', 'discriminant_analysis.py', 'kernel_approximation.pyc', 'base.py', 'random_projection.pyc', 'setup.pyc', 'kernel_approximation.py', 'grid_search.py', 'discriminant_analysis.pyc', 'mixture', 'manifold', 'externals', 'svm', 'feature_extraction', 'learning_curve.pyc'] >>> import zope >>> print(dir(zope)) ['__doc__', '__name__', '__path__'] >>> print(listdir(zope.__path__[0])) ['interface'] >>> zope.interface Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'interface' >>> sklearn.lda Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'lda' 
+7
python anaconda
source share
4 answers

sad but true ... your mistake is real .. but also a warning message. Use sklearn.discriminant_analysis.LinearDiscriminantAnalysis from now on. How to deal with another possible persisting error is also updated in my answer. Enjoy it!

 import warnings from .discriminant_analysis import LinearDiscriminantAnalysis as _LDA warnings.warn("lda.LDA has been moved to " "discriminant_analysis.LinearDiscriminantAnalysis " "in 0.17 and will be removed in 0.19", DeprecationWarning) class LDA(_LDA): """ Alias for :class:`sklearn.discriminant_analysis.LinearDiscriminantAnalysis`. .. deprecated:: 0.17 This class will be removed in 0.19. Use :class:`sklearn.discriminant_analysis.LinearDiscriminantAnalysis` instead. """ pass 

There are no errors when starting under the code:

 import sklearn from sklearn import discriminant_analysis from os import listdir print(dir(sklearn)) print(listdir(sklearn.__path__[0])) print discriminant_analysis.LinearDiscriminantAnalysis() 

fragment output:

[Assume_FINITE ', ...]

['base.py', ...]

LinearDiscriminantAnalysis (n_components = None, priors = None, shrinkage = None, solver = 'svd', store_covariance = False, tol = 0.0001)

It seems your code is going wrong somewhere and somehow. At the moment, your best option:

1 - delete your scikit-image, sklearn and zope folders from the .. / site -packages folder;

2 - delete the folders + contents of scikit_image-0.13.0-py2.7.egg-info, scikit_learn-0.19.1-py2.7.egg-info and the installation folder zope . in the trash;

3 - delete folders from trashbin (prevents binding to folders in the basket);

4 -run pip install scikit-image / sklearn / zope with the option --no-cache-dir ;

5 Voila ... you will again get running skimage, sklearn and zope.

Enjoy it!

+6
source share

It is not that you cannot download them. As you can see, you have successfully completed the import without error messages. However, it seems that the zope and sklearn modules do not have the attributes that you are trying to use with them.

to try:

from zope.interface import Interface

and the same for sklearn:

from sklearn import lda

Hope this helps. If not, try reinstalling the packages.


Please note that : you simply cannot just use pip install package , because you also need to install other dependencies. Below are the installation instructions pages for:

+2
source share

The attribute error that you represent is the expected behavior of Python3. You upgraded from Python 2 to Python 3 Since there are many differences between version families ... more about this here: https://docs.python.org/3/howto/pyporting.html

To load the sklearn.lda module, you must explicitly import part of the module you need.

from sklearn import lda

or

import sklearn.lda

Hope this answers your question!

+1
source share

A useful way to work around this problem in the future is to use virtual environments. This will allow you to have different versions of packages running on the same computer. This means that you can upgrade your packages for your new code, but you can still run your old code on the same computer.

If you are using Anaconda, then https://conda.io/docs/using/envs.html is a description.

If you've ever used the cpython virtualenvwrapper.readthedocs.io/en/latest/install.html distribution, this is an awesome tool.

While this will not solve your problem directly, spending an hour to work with it will stop dependency problems for you in the future, saving you a lot of time in the future.

0
source share

All Articles