I typed the following command
import matplotlib.image as mpimg
img = mpimg.imread("test.jpg")
I get the following error:
TypeError Traceback (most recent call last)
<ipython-input-12-009ac1935016> in <module>()
----> 1 img = mpimg.imread("test.jpg")
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in imread(fname, format)
1225
1226 if ext not in handlers:
-> 1227 im = pilread(fname)
1228 if im is None:
1229 raise ValueError('Only know how to handle extensions: %s; '
/usr/local/lib/python2.7/dist-packages/matplotlib/image.pyc in pilread(fname)
1203 except ImportError:
1204 return None
-> 1205 with Image.open(fname) as image:
1206 return pil_to_array(image)
1207
TypeError: 'NoneType' object is not callable
Related
I want to read a pickle file into a data frame. However, I get the following error message and I don't know how to solve the issue.
df_batches = pd.read_pickle(folder_in / "batches_and_phases.p")
Error Message:
AttributeError Traceback (most recent call last)
File ~\Master_Thesis\mypython\lib\site-packages\pandas\io\pickle.py:205, in read_pickle(filepath_or_buffer, compression, storage_options)
204 warnings.simplefilter("ignore", Warning)
--> 205 return pickle.load(handles.handle)
206 except excs_to_catch:
207 # e.g.
208 # "No module named 'pandas.core.sparse.series'"
209 # "Can't get attribute '__nat_unpickle' on <module 'pandas._libs.tslib"
File ~\Master_Thesis\mypython\lib\site-packages\pandas\_libs\internals.pyx:750, in pandas._libs.internals.BlockManager.__setstate__()
File ~\Master_Thesis\mypython\lib\site-packages\pandas\_libs\internals.pyx:767, in pandas._libs.internals.BlockManager.__setstate__()
File ~\Master_Thesis\mypython\lib\site-packages\pandas\core\internals\blocks.py:2143, in ensure_block_shape(values, ndim)
2142 if values.ndim < ndim:
-> 2143 if not is_1d_only_ea_dtype(values.dtype):
2144 # TODO(EA2D): https://github.com/pandas-dev/pandas/issues/23023
2145 # block.shape is incorrect for "2D" ExtensionArrays
2146 # We can't, and don't need to, reshape.
2147 values = cast("np.ndarray | DatetimeArray | TimedeltaArray", values)
File ~\Master_Thesis\mypython\lib\site-packages\pandas\core\arrays\interval.py:624, in IntervalArray.dtype(self)
622 #property
623 def dtype(self) -> IntervalDtype:
--> 624 return self._dtype
AttributeError: 'IntervalArray' object has no attribute '_dtype'
Thank you!
Hi i am having issues with loading the .s2p file
when i ran the following code
import skrf as rf
from skrf import Network, Frequency
data1 = rf.Network('/Users/pradeeps/Desktop/Project/meas2018_07_06/300MHzNLOSX1DPS.s2p')
It showed the following error as shown below
---------------------------------------------------------------------------
UnpicklingError Traceback (most recent call last)
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:450, in Network.__init__(self, file, name, params, comments, f_unit, s_def, **kwargs)
449 try:
--> 450 self.read(fid)
451 except UnicodeDecodeError: # Support for pickles created in Python2 and loaded in Python3
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:2357, in Network.read(self, *args, **kwargs)
2356 from .io.general import read
-> 2357 self.copy_from(read(*args, **kwargs))
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/io/general.py:140, in read(file, *args, **kwargs)
139 try:
--> 140 obj = pickle.load(fid, *args, **kwargs)
141 except (UnpicklingError, UnicodeDecodeError) as e:
142 # if fid is seekable then reset to beginning of file
UnpicklingError: invalid load key, '3'.
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
Untitled-1.ipynb Cell 2' in <cell line: 1>()
----> 1 data1 = rf.Network('/Users/pradeeps/Desktop/Project/meas2018_07_06/300MHzNLOSX1DPS.s2p')
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:458, in Network.__init__(self, file, name, params, comments, f_unit, s_def, **kwargs)
456 filename = fid.name
457 fid.close()
--> 458 self.read_touchstone(filename, self.encoding)
460 if name is None and isinstance(file, str):
461 name = os.path.splitext(os.path.basename(file))[0]
File ~/Desktop/Project/project/lib/python3.10/site-packages/skrf/network.py:1956, in Network.read_touchstone(self, filename, encoding)
1953 touchstoneFile = touchstone.Touchstone(filename, encoding=encoding)
1955 if touchstoneFile.get_format().split()[1] != 's':
-> 1956 raise NotImplementedError('only s-parameters supported for now.')
1958 self.comments = touchstoneFile.get_comments()
1960 try:
NotImplementedError: only s-parameters supported for now.
As shown in this particular code i used scikit-rf is there any other package that i should use in this particular instance or am i doing anything wrong.
Thank you
I try to run this peace of code on Colab:
BATCH_SIZE = 256
train_dataset = tf.data.TextLineDataset(
'/content/training_set.csv'
).map(decode_csv).batch(BATCH_SIZE)
eval_dataset = tf.data.TextLineDataset(
'/content/eval_set.csv'
).map(decode_csv).batch(BATCH_SIZE)
but always get this error:
AttributeError
Traceback (most recent call last)
<ipython-input-22-b4dab8cd6263> in <module>()
1 BATCH_SIZE = 256
2
----> 3 train_dataset = tf.data.TextLineDataset('/content/training_set.csv').map(decode_csv).batch(BATCH_SIZE)
4
5 eval_dataset = tf.data.TextLineDataset('/content/eval_set.csv').map(decode_csv).batch(BATCH_SIZE)
10 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
697 except Exception as e: # pylint:disable=broad-except
698 if hasattr(e, 'ag_error_metadata'):
--> 699 raise e.ag_error_metadata.to_exception(e)
700 else:
701 raise
AttributeError: in user code:
File "<ipython-input-15-099bb5339c8f>", line 18, in decode_csv *
filename, pawpularity = tf.op.decode_csv(csv_row, record_defaults)
AttributeError: module 'tensorflow' has no attribute 'op'
I have searched for that topic and I found the following code
from PIL import Image, ImageSequence
im = Image.open("MySample.tiff")
for i, page in enumerate(ImageSequence.Iterator(im)):
page.save("Page_%d.png" % i)
The code works for some tiff files but I encountered an error with one of them
The traceback is like that
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-2-12bbb3a559f8> in <module>
5 im = Image.open("MySample.tiff")
6 for i, page in enumerate(ImageSequence.Iterator(im)):
----> 7 page.save("Page_%d.png" % i)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py in save(self, fp, format, **params)
2128
2129 # may mutate self!
-> 2130 self._ensure_mutable()
2131
2132 save_all = params.pop("save_all", False)
C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py in _ensure_mutable(self)
617 def _ensure_mutable(self):
618 if self.readonly:
--> 619 self._copy()
620 else:
621 self.load()
C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py in _copy(self)
610
611 def _copy(self):
--> 612 self.load()
613 self.im = self.im.copy()
614 self.pyaccess = None
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py in load(self)
1086 def load(self):
1087 if self.tile and self.use_load_libtiff:
-> 1088 return self._load_libtiff()
1089 return super().load()
1090
C:\ProgramData\Anaconda3\lib\site-packages\PIL\TiffImagePlugin.py in _load_libtiff(self)
1190
1191 if err < 0:
-> 1192 raise OSError(err)
1193
1194 return Image.Image.load(self)
OSError: -9
I'm working with a Jupyter notebook. I'm trying to import a file called main.py which contains 2 lines:
import os
ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) # This is your Project Root
My code:
import os
%load main.py
from main import ROOT_DIR
I'm getting
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
....\site-packages\IPython\core\interactiveshell.py in find_user_code(self, target, raw, py_only, skip_encoding_cookie, search_ns)
3282 try: # User namespace
-> 3283 codeobj = eval(target, self.user_ns)
3284 except Exception:
<string> in <module>()
NameError: name 'main' is not defined
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-3-1f13faed25b1> in <module>()
1 import os
----> 2 get_ipython().run_line_magic('load', 'main.py')
3 from main import ROOT_DIR
....\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2129 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2130 with self.builtin_trap:
-> 2131 result = fn(*args,**kwargs)
2132 return result
2133
<decorator-gen-48> in load(self, arg_s)
....\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
....\site-packages\IPython\core\magics\code.py in load(self, arg_s)
342 search_ns = 'n' in opts
343
--> 344 contents = self.shell.find_user_code(args, search_ns=search_ns)
345
346 if 's' in opts:
....\site-packages\IPython\core\interactiveshell.py in find_user_code(self, target, raw, py_only, skip_encoding_cookie, search_ns)
3284 except Exception:
3285 raise ValueError(("'%s' was not found in history, as a file, url, "
-> 3286 "nor in the user namespace.") % target)
3287
3288 if isinstance(codeobj, str):
ValueError: 'main.py' was not found in history, as a file, url, nor in the user namespace.
What am I doing wrong?