importing pandas module, Attribute error with "pickle" module - python

My code: import pandas
Error showing:
File "D:/.../pandas_test.py", line 1, in <module>
import pandas
File "C:\...\anaconda3\lib\site-packages\pandas\__init__.py", line 55, in <module>
from pandas.core.api import (
File "C:\...\anaconda3\lib\site-packages\pandas\core\api.py", line 29, in <module>
from pandas.core.groupby import Grouper, NamedAgg
File "C:\...\anaconda3\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
from pandas.core.groupby.generic import DataFrameGroupBy, NamedAgg, SeriesGroupBy
File "C:\...\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 60, in <module>
from pandas.core.frame import DataFrame
File "C:\...\anaconda3\lib\site-packages\pandas\core\frame.py", line 104, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "C:\...\anaconda3\lib\site-packages\pandas\core\generic.py", line 151, in <module>
class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
File "C:\...\anaconda3\lib\site-packages\pandas\core\generic.py", line 2670, in NDFrame
protocol: int = pickle.HIGHEST_PROTOCOL,
AttributeError: module 'pickle' has no attribute 'HIGHEST_PROTOCOL'
Process finished with exit code 1
I worked with pandas module last week with the same PC there was no problem. I faced this error today. Don't know much about pickle module.
I've reinstalled pandas module nothing changed.
Python version: 3.7.6
Windows 10

Related

AttributeError: module 'dill' has no attribute '_dill' when importing datasets

In Python 3.9.13, when importing the package datasets, I get an AttributeError from the dill package.
I am running the following versions :
datasets : 2.9.0
dill : 0.3.6
Is there any specific modification of the packages needed ?
Thank you for your help
From :
import datasets
i get :
import datasets
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\__init__.py", line 43, in <module>
from .arrow_dataset import Dataset
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\arrow_dataset.py", line 66, in <module>
from .arrow_writer import ArrowWriter, OptimizedTypedSequence
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\arrow_writer.py", line 27, in <module>
from .features import Features, Image, Value
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\features\__init__.py", line 17, in <module>
from .audio import Audio
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\features\audio.py", line 12, in <module>
from ..download.streaming_download_manager import xopen
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\download\__init__.py", line 9, in <module>
from .download_manager import DownloadManager, DownloadMode
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\download\download_manager.py", line 36, in <module>
from ..utils.py_utils import NestedDataStructure, map_nested, size_str
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\utils\py_utils.py", line 602, in <module>
class Pickler(dill.Pickler):
File "C:\ProgramData\Anaconda3\lib\site-packages\datasets\utils\py_utils.py", line 605, in Pickler
dispatch = dill._dill.MetaCatchingDict(dill.Pickler.dispatch.copy())
AttributeError: module 'dill' has no attribute '_dill'```

Python problem with extensions in virtual enviroment [duplicate]

This question already has an answer here:
unknown version in python library pyparsing
(1 answer)
Closed 1 year ago.
I am using python 3.7.5 version, however I downloaded 3.6 version for specific project and created virtual enviroment, installed required extensions (numpy, matplotlib...). However when I try to run python script, there comes a lot of errors related to extensions. The code worked flawlessly with 3.7 version of python. Any thoughts what can be wrong?
File "c:/Users/zabul/OneDrive/Desktop/pyCode/Data_observation.py", line 4, in <module>
import pandas as pd
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-packages\pandas\__init__.py",
line 55, in <module>
from pandas.core.api import (
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-packages\pandas\core\api.py",
line 24, in <module>
from pandas.core.groupby import Grouper, NamedAgg
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\core\groupby\__init__.py", line 1, in <module>
from pandas.core.groupby.generic import ( # noqa: F401
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\core\groupby\generic.py", line 44, in <module>
from pandas.core.frame import DataFrame
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-packages\pandas\core\frame.py",
line 115, in <module>
from pandas.core.series import Series
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\core\series.py", line 84, in <module>
import pandas.plotting
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\plotting\__init__.py", line 59, in <module>
from pandas.plotting._core import (
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\plotting\_core.py", line 17, in <module>
import pandas.plotting._matplotlib # noqa
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\plotting\_matplotlib\__init__.py", line 3, in <module>
from pandas.plotting._matplotlib.boxplot import (
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pandas\plotting\_matplotlib\boxplot.py", line 4, in <module>
from matplotlib.artist import setp
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\matplotlib\__init__.py", line 128, in <module>
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\matplotlib\rcsetup.py", line 29, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\matplotlib\fontconfig_pattern.py", line 26, in <module>
from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
File "C:\Users\zabul\OneDrive\Desktop\pyCode\.virtenv\lib\site-
packages\pyparsing\__init__.py", line 130, in <module>
__version__ = __version_info__.__version__
AttributeError: 'version_info' object has no attribute '__version__'
This subject unknown version in python library pyparsing is the same as this one. Your error seems to be on pyparsing.

Error after updating scikit-learn to version 0.20.1 : cannot import name 'Empty' from 'queue'

I upgraded scikit-learn to version 0.20.1 using anaconda3 after getting an error message concerning balanced_accuracy_score from metrics in scikit-learn. This is apparently not available in version 0.19.
After this upgrade i get the following error:
Traceback (most recent call last):
File "test4.py", line 4, in <module>
from sklearn import metrics
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\__init__.py", line 6
4, in <module>
from .base import clone
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\base.py", line 13, i
n <module>
from .utils.fixes import signature
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\utils\__init__.py",
line 14, in <module>
from . import _joblib
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\utils\_joblib.py", l
ine 22, in <module>
from ..externals import joblib
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\__i
nit__.py", line 119, in <module>
from .parallel import Parallel
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\par
allel.py", line 28, in <module>
from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\_pa
rallel_backends.py", line 22, in <module>
from .executor import get_memmapping_executor
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\exe
cutor.py", line 14, in <module>
from .externals.loky.reusable_executor import get_reusable_executor
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\__init__.py", line 13, in <module>
from .reusable_executor import get_reusable_executor
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\reusable_executor.py", line 11, in <module>
from .process_executor import ProcessPoolExecutor, EXTRA_QUEUED_CALLS
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\process_executor.py", line 82, in <module>
from .backend.queues import Queue, SimpleQueue, Full
File "C:\Users\Pieter\Anaconda3\lib\site-packages\sklearn\externals\joblib\ext
ernals\loky\backend\queues.py", line 21, in <module>
from multiprocessing.queues import Full
File "C:\Users\Pieter\Anaconda3\lib\multiprocessing\queues.py", line 20, in <m
odule>
from queue import Empty, Full
ImportError: cannot import name 'Empty' from 'queue' (C:\Users\Pieter\Python pro
gs\queue.py)
Are you running this program from "C:\Users\Pieter\Python progs"?
Looks like you have a file named queue.py in "C:\Users\Pieter\Python pro
gs\" which is shadowing the actual module queue in multiprocessing lib. And hence the error.
There are two possible reasons for this:
Maybe this line:
from queue import Empty, Full
has been added in new version, so earlier it did not error even when your custom made queue.py was present.
Maybe you have created your queue.py recently after updating the scikit-learn and the above line was always present. In this case, error should occur on both versions.
Rename your program from queue.py and auto-compiled queue.pyc
to something else and it should work.

not able to resolve AttributeError: module 'pandas' has no attribute 'read_csv'

I am using Python 3 and working on an ML project. My code ran fine for the first time but suddenly, out of nowhere, this error popped up.
Traceback (most recent call last):
File "<ipython-input-2-3ae66814e4b2>", line 1, in <module>
import pandas as pd
File "C:\Users\ruhani\Anaconda3\lib\site-packages\pandas\__init__.py", line 42, in <module>
from pandas.core.api import *
File "C:\Users\ruhani\Anaconda3\lib\site-packages\pandas\core\api.py", line 10, in <module>
from pandas.core.groupby import Grouper
File "C:\Users\ruhani\Anaconda3\lib\site-packages\pandas\core\groupby.py", line 49, in <module>
from pandas.core.frame import DataFrame
File "C:\Users\ruhani\Anaconda3\lib\site-packages\pandas\core\frame.py", line 67, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "C:\Users\ruhani\Anaconda3\lib\site-packages\pandas\core\generic.py", line 36, in <module>
trainDF=pd.read_csv("C:\\Users\\ruhani\\Desktop\\Minor Project\\projects\\train.csv\\train.csv")
AttributeError: module 'pandas' has no attribute 'read_csv'
Please help me as I am new to Python and Machine Learning.

Error '__init__ called too many times' while monkey patching

I am using eventlet module. When I try to monkey_patch the code exits with error:
'__init__ called too many times'
Here's the code that's causing problem:
from eventlet import *
patcher.monkey_patch(all=True)
import os, glob, pandas, logging
import numpy as np
import boto3
import datetime
The import works fine, but monkey patching is the step where I see error.
EDIT:
Here's the stack trace:
Traceback (most recent call last):
File "check.py", line 4, in <module>
import os, glob, pandas, logging
File "d:\Python\Anaconda\lib\site-packages\pandas\__init__.py", line 45, in <module>
from pandas.core.api import *
File "d:\Python\Anaconda\lib\site-packages\pandas\core\api.py", line 9, in <module>
from pandas.core.groupby import Grouper
File "d:\Python\Anaconda\lib\site-packages\pandas\core\groupby.py", line 15, in <module>
from pandas.core.frame import DataFrame
File "d:\Python\Anaconda\lib\site-packages\pandas\core\frame.py", line 32, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "d:\Python\Anaconda\lib\site-packages\pandas\core\generic.py", line 16, in <module>
from pandas.core.internals import BlockManager
File "d:\Python\Anaconda\lib\site-packages\pandas\core\internals.py", line 22, in <module>
from pandas.sparse.array import _maybe_to_sparse, SparseArray
File "d:\Python\Anaconda\lib\site-packages\pandas\sparse\array.py", line 19, in <module>
import pandas.core.ops as ops
File "d:\Python\Anaconda\lib\site-packages\pandas\core\ops.py", line 15, in <module>
import pandas.computation.expressions as expressions
File "d:\Python\Anaconda\lib\site-packages\pandas\computation\expressions.py", line 15, in <module>
import numexpr as ne
File "d:\Python\Anaconda\lib\site-packages\numexpr\__init__.py", line 40, in <module>
from numexpr.expressions import E
File "d:\Python\Anaconda\lib\site-packages\numexpr\expressions.py", line 81, in <module>
_context = Context({})
File "d:\Python\Anaconda\lib\site-packages\numexpr\expressions.py", line 67, in __init__
raise SystemError('__init__ called too many times')
SystemError: __init__ called too many times
Try to run it without all=True:
patcher.monkey_patch()
(you basically have called a class several times)
This is an issue with Windows machines in particular.. patcher.monkey_patch() is working perfectly fine for me in OSX, while the same code returns with -
SystemError: init called too many times for my colleagues using wondows machines ..
I am still searching for a solution for this issue.

Categories