How can I eliminate "UnpicklingError: invalid load key, '\x00'" in win32com? - python-3.x

I'm using the latest version of win32com on Windows 7 and Python 3.6. import win32com.client working fine until recently. I'm now getting an UnpicklingError exception.
I've tried reinstalling the latest version globally as well as in a separate virtual environment.
In [1]: import win32com.client
---------------------------------------------------------------------------
UnpicklingError Traceback (most recent call last)
<ipython-input-1-acfbed532f32> in <module>()
----> 1 import win32com.client
C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\__init__.py in <module>()
9 import pythoncom
10 from . import dynamic
---> 11 from . import gencache
12 import sys
13 import pywintypes
C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py in <module>()
658
659 # Boot up
--> 660 __init__()
661
662 def usage():
C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py in __init__()
58 # Initialize the module. Called once explicitly at module import below
59 try:
---> 60 _LoadDicts()
61 except IOError:
62 Rebuild()
C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\gencache.py in _LoadDicts()
111 try:
112 p = pickle.Unpickler(f)
--> 113 version = p.load()
114 global clsidToTypelib
115 clsidToTypelib = p.load()
UnpicklingError: invalid load key, '\x00'.

Related

How to resolve this error when trying to use Pandas Styling?

I am running Python 3.6.5 and Pandas 0.25.2.
On attempting to style a pandas dataframe I am getting a specific error which can be generated by simplifying to this code:
import pandas as pd
import pandas.io.formats.style
The summary of the error generated is:
ImportError: The 'packaging._typing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
The full error message is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-e9b944578fec> in <module>()
1 import pandas as pd
----> 2 import pandas.io.formats.style
~\Anaconda3\lib\site-packages\pandas\io\formats\style.py in <module>()
48
49
---> 50 class Styler:
51 """
52 Helps style a DataFrame or Series according to the data with HTML and CSS.
~\Anaconda3\lib\site-packages\pandas\io\formats\style.py in Styler()
109 """
110
--> 111 loader = jinja2.PackageLoader("pandas", "io/formats/templates")
112 env = jinja2.Environment(loader=loader, trim_blocks=True)
113 template = env.get_template("html.tpl")
~\Anaconda3\lib\site-packages\jinja2\loaders.py in __init__(self, package_name, package_path, encoding)
220 def __init__(self, package_name, package_path='templates',
221 encoding='utf-8'):
--> 222 from pkg_resources import DefaultProvider, ResourceManager, \
223 get_provider
224 provider = get_provider(package_name)
~\Anaconda3\lib\site-packages\pkg_resources\__init__.py in <module>()
79 from pkg_resources.extern import appdirs
80 from pkg_resources.extern import packaging
---> 81 __import__('pkg_resources.extern.packaging.version')
82 __import__('pkg_resources.extern.packaging.specifiers')
83 __import__('pkg_resources.extern.packaging.requirements')
~\Anaconda3\lib\site-packages\pkg_resources\_vendor\packaging\version.py in <module>()
9
10 from ._structures import Infinity, NegativeInfinity
---> 11 from ._typing import TYPE_CHECKING
12
13 if TYPE_CHECKING: # pragma: no cover
~\Anaconda3\lib\site-packages\pkg_resources\extern\__init__.py in load_module(self, fullname)
52 "normally this is bundled with this package so if you get "
53 "this warning, consult the packager of your "
---> 54 "distribution.".format(**locals())
55 )
56
I have tried reinstalling and upgrading the pandas installation, but each time I get the same error. This is being doine through an Anaconda environment.
Has anyone seen this error before? Is there a more detailed explanation that anyone can provide in an effort to solve this issue so that I can get the pandas styling working.
Thanks!
The correct way to do this is by:
from pandas.io.formats import style
This is because style is a module of pandas.io.formats package and the correct syntax is:
from package import module

Trouble importing modules into ipython

On a freshly installed Windows 10 machine, I installed the newest 64bit version of anaconda. Now when I try importing modules into ipython, I get errors. Some sample errors are reproduced below.
I am new to Python and Programming, so would appreciate a bit of help. This is a brand new Lenovo laptop, so there's no scope for any Python version conflict etc. (since nothing was installed on it earlier).
In [1]: import sklearn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn
C:\Software\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
74 else:
75 from . import __check_build
---> 76 from .base import clone
77 from .utils._show_versions import show_versions
78
C:\Software\anaconda3\lib\site-packages\sklearn\base.py in <module>
11 import re
12
---> 13 import numpy as np
14
15 from . import __version__
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt
C:\Software\anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
136 # cbook must import matplotlib only within function
137 # definitions, so it is safe to import from it here.
--> 138 from . import cbook, rcsetup
139 from matplotlib.cbook import (
140 MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)
C:\Software\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in <module>
29 from weakref import WeakMethod
30
---> 31 import numpy as np
32
33 import matplotlib
C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
138
139 # Allow distributors to run custom init code
--> 140 from . import _distributor_init
141
142 from . import core
C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
32
33 with RTLD_for_MKL():
---> 34 from . import _mklinit
35
36 del RTLD_for_MKL
ImportError: DLL load failed: The specified module could not be found.
In [3]: import pystan
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-ca8618bb8e4a> in <module>
----> 1 import pystan
ModuleNotFoundError: No module named 'pystan'
In [4]:
After a lot of google searching, I found a few sites that touch upon some closely related issues (ex. https://github.com/stan-dev/pystan/issues/520). It so happens that one needs to add some anaconda directroties to the Windows path. I added anaconda/Library/bin, anaconda/Scripts to the path. Now everything is working as expected.

ImportError: DLL load failed: The specified procedure could not be found. (import sklearn)

When I import sklearn, it throws this ImportError(DLL load failed: The specified procedure could not be found.)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>()
----> 1 import sklearn
~\Anaconda3\lib\site-packages\sklearn\__init__.py in <module>()
62 else:
63 from . import __check_build
---> 64 from .base import clone
65 from .utils._show_versions import show_versions
66
~\Anaconda3\lib\site-packages\sklearn\base.py in <module>()
11 from scipy import sparse
12 from .externals import six
---> 13 from .utils.fixes import signature
14 from . import __version__
15
~\Anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>()
11
12 from .murmurhash import murmurhash3_32
---> 13 from .validation import (as_float_array,
14 assert_all_finite,
15 check_random_state, column_or_1d, check_array,
~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>()
20
21 from ..externals import six
---> 22 from ..utils.fixes import signature
23 from .. import get_config as _get_config
24 from ..exceptions import NonBLASDotWarning
~\Anaconda3\lib\site-packages\sklearn\utils\fixes.py in <module>()
81 return stats.boxcox(x, lmbda)
82 else:
---> 83 from scipy.special import boxcox # noqa
84
85
~\Anaconda3\lib\site-packages\scipy\special\__init__.py in <module>()
638 from .sf_error import SpecialFunctionWarning, SpecialFunctionError
639
--> 640 from ._ufuncs import *
641
642 from .basic import *
ImportError: DLL load failed: The specified procedure could not be found.
If you already have a working installation of numpy and scipy, then do this:
pip install -U scikit-learn
otherwise:
conda install scikit-learn
finally check for updates:
conda update pip

boxsdk demo/auth.py fails on from boxsdk import OAuth2

Running on python 3.6 (anaconda)
Tried to run authenticate() within boxsdk: demo/auth.py and get error on import.
Looks like error is happening in /anaconda/lib/python3.6/site-packages/boxsdk/object/events.py....
class EventsStreamType(with_metaclass(ExtendableEnumMeta, TextEnum)):
I did look thru other posts but don't see solution
python - Fix 'new enumerations must be created as' - Stack Overflow
boxsdk 1.x does not import in python 3.6.0 · Issue #195 · box/box ...
ERROR
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-33-e86018378e6f> in <module>()
9 from wsgiref.simple_server import WSGIServer, WSGIRequestHandler, make_server
10
---> 11 from boxsdk import OAuth2
12
13
/anaconda/lib/python3.6/site-packages/boxsdk/__init__.py in <module>()
4
5 from .auth import JWTAuth, OAuth2
----> 6 from .client import * # pylint:disable=wildcard-import,redefined-builtin
7 from .object import * # pylint:disable=wildcard-import,redefined-builtin
8 from .version import __version__
/anaconda/lib/python3.6/site-packages/boxsdk/client/__init__.py in <module>()
3 from __future__ import unicode_literals, absolute_import
4
----> 5 from .client import Client
6 from .developer_token_client import DeveloperTokenClient
7 from .development_client import DevelopmentClient
/anaconda/lib/python3.6/site-packages/boxsdk/client/client.py in <module>()
10 from ..object.folder import Folder
11 from ..object.search import Search
---> 12 from ..object.events import Events
13 from ..object.file import File
14 from ..object.group import Group
/anaconda/lib/python3.6/site-packages/boxsdk/object/events.py in <module>()
13
14 # pylint:disable=too-many-ancestors
---> 15 class EventsStreamType(with_metaclass(ExtendableEnumMeta, TextEnum)):
16 """An enum of all possible values of the `stream_type` parameter for user events.
17
/anaconda/lib/python3.6/enum.py in __prepare__(metacls, cls, bases)
117 enum_dict = _EnumDict()
118 # inherit previous flags and _generate_next_value_ function
--> 119 member_type, first_enum = metacls._get_mixins_(bases)
120 if first_enum is not None:
121 enum_dict['_generate_next_value_'] = getattr(first_enum, '_generate_next_value_', None)
/anaconda/lib/python3.6/enum.py in _get_mixins_(bases)
437 # base is now the last base in bases
438 if not issubclass(base, Enum):
--> 439 raise TypeError("new enumerations must be created as "
440 "`ClassName([mixin_type,] enum_type)`")
441
TypeError: new enumerations must be created as `ClassName([mixin_type,] enum_type)`

sklearn import error. No module named winreg on ubuntu 14.04

When I try to import a module from sklearn a receive an error:
In [1]: import sklearn
In [2]: from sklearn.linear_model import Lasso
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-b932cb9c16f8> in <module>()
----> 1 from sklearn.linear_model import Lasso
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/__init__.py in <module>()
10 # complete documentation.
11
---> 12 from .base import LinearRegression
13
14 from .bayes import BayesianRidge, ARDRegression
/usr/local/lib/python3.4/dist-packages/sklearn/linear_model/base.py in <module>()
26 from ..externals.joblib import Parallel, delayed
27 from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
---> 28 from ..utils import as_float_array, atleast2d_or_csr, safe_asarray
29 from ..utils.extmath import safe_sparse_dot
30 from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
/usr/local/lib/python3.4/dist-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array, check_arrays, safe_asarray,
12 assert_all_finite, array2d, atleast2d_or_csc,
13 atleast2d_or_csr, warn_if_not_float,
/usr/local/lib/python3.4/dist-packages/sklearn/utils/validation.py in <module>()
15
16 from ..externals import six
---> 17 from .fixes import safe_copy
18
19
/usr/local/lib/python3.4/dist-packages/sklearn/utils/fixes.py in <module>()
103
104 try:
--> 105 with ignore_warnings():
106 # Don't raise the numpy deprecation warnings that appear in
107 # 1.9
/usr/local/lib/python3.4/dist-packages/sklearn/utils/testing.py in __enter__(self)
297
298 def __enter__(self):
--> 299 clean_warning_registry() # be safe and not propagate state + chaos
300 warnings.simplefilter('always')
301 if self._entered:
/usr/local/lib/python3.4/dist-packages/sklearn/utils/testing.py in clean_warning_registry()
582 reg = "__warningregistry__"
583 for mod in sys.modules.copy().values():
--> 584 if hasattr(mod, reg):
585 getattr(mod, reg).clear()
586
/usr/lib/python3/dist-packages/scipy/lib/six.py in __getattr__(self, attr)
114 if attr in ("__file__", "__name__") and self.mod not in sys.modules:
115 raise AttributeError
--> 116 _module = self._resolve()
117 value = getattr(_module, attr)
118 setattr(self, attr, value)
/usr/lib/python3/dist-packages/scipy/lib/six.py in _resolve(self)
103
104 def _resolve(self):
--> 105 return _import_module(self.mod)
106
107 def __getattr__(self, attr):
/usr/lib/python3/dist-packages/scipy/lib/six.py in _import_module(name)
74 def _import_module(name):
75 """Import module, returning the module after the last dot."""
---> 76 __import__(name)
77 return sys.modules[name]
78
ImportError: No module named 'winreg'
In [3]:
I have installed sklearn with the command pip3 as explained in the official documentation
In [3]: sklearn.__version__
Out[3]: '0.15.1'
winreg should be a module available only for windows... how can I solve this?
EDIT:
This is the command that I have used to install sklearn :
sudo pip3 install -U scikit-learn
I have solved removing sklearn and installing the git version as explained here
https://askubuntu.com/questions/449326/installation-error-in-sklearn-for-python3

Resources