flow_from_directory cannot find path error in Spyder - image

I saw a lot of questions about the subject here but unfortunately didn't find one that solved my problem.I have the following code:
import numpy as np
from numpy import asarray
from PIL import Image
import tensorflow as tf
import keras
from keras.preprocessing.image import ImageDataGenerator
datagen =ImageDataGenerator()
train_it = datagen.flow_from_directory("C:/Users/agns1/Downloads/by_class.zip/by_class/4a/hsf_1", class_mode='binary', batch_size=10)
the data is from MNIST data set . and the error is :
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Users/agns1/Downloads/by_class.zip/by_class/4a/hsf_1'
unfortunately, I cant seem to understand what is is the problem is it because of the zip ? Thank you:)

Related

cannot import name 'BlobServiceClient' even if 'Azure-blob-Storage' latest version azure-storage-blob==12.9.0 is installed

I am trying to execute a script in 'Azure Notebooks' to upload blob to Azure Data lake Gen 2 using 'Azure-storage-blob', but couldn't as I am unable to import 'BlobServiceClient'. I have latest version of 'Azure-storage-blob' - 12.9.0 installed. But still facing issue in importing 'BlobServiceClient'
Below is the code
import azure.storage.blob
from azure.storage.blob import blockblobservice
import os, uuid
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
Below is the error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-278-283cd1817c6e> in <module>
7 from azure.storage.blob import blockblobservice
8 import os, uuid
----> 9 from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
10
11 try:
ImportError: cannot import name 'BlobServiceClient'
Try with this
1. Uninstall azure-storage-blob using: pip uninstall azure-storage-blob.
2. Reinstall azure-storage-blob using: pip install azure-storage-blob.
And from your code from azure.storage.blob import blockblobservice you are trying to import blockblobservice . In newer versions of azure-storage-blob the import BlockBlobService has been renamed to BlobServiceClient.
I tried with this import statement
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
OUTPUT:
For more details refer this document

cx_Freeze encodings for creating macOS application

I am trying to create a standalone Python3 macOS application including tkinter and selenium by using cx_Freeze. There are three files in my project:
tkinter_tab3.py (contains GUI)
user.txt (contains user info)
ver004.py (called from tkinter_tab3.py and executes tasks)
I created the following setup.py file with tkinter_tab3.py being the file to be turned into the executable:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = ['encodings'], excludes = [])
includefiles = ['user.txt', 'ver004.py']
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('tkinter_tab3.py', base=base, targetName = 'suprbotcho')
]
setup(name='suprbotcho',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
However, when I run $python3 setup.py build then click on the created executable, I receive this error back in the terminal:
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
In addition, when I run $python3 setup.py bdist.mac and $python3 setup.py bdist.dmg, I receive the following error:
build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):
error: can't copy 'build/suprbotcho-1.0.app/Contents/MacOS/lib/numpy/core/lib/libnpymath.a(npy_math.o):': doesn't exist or not a regular file
I do not understand where I am going wrong because I have read other posts about the encodings problem however I found no progress after trying out the posted solutions.
Here are the imports for each python file:
tkinter_tab3.py
from tkinter import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from ver004 import SuPrBoTcHo, InIt_UsEr
ver004.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import numpy as np
import time
from datetime import datetime
from threading import Timer
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
If I could get help on fixing this particular problem, that would be great. If you have any particular questions, feel free to let me know.
(python version: 3.6.3)
I had the same problem.
The solution was to upgrade cxfreeze to the latest version, i.e do the following steps-
pip install -U cx_Freeze==6.0.b1

Solving optimisation sub-instances in Parallel, using Pyomo ( Traceback )

I am trying to solve an energy model with Benders Decomposition.
In the model we are creating a master model and several sub models.
And I want to solve the sub models in parallel, and I saw an example here.
This is what I am using in the code:
from pyomo.opt.base import SolverFactory
from pyomo.opt.parallel import SolverManagerFactory
from pyomo.opt.parallel.manager import solve_all_instances
subs = []
for m in range(0, len(supportsteps)-1):
subs.append(urbs.create_model(data,
range(supportsteps[m], supportsteps[m+1]+1),
supportsteps, type=1))
solver_manager = SolverManagerFactory("pyro")
solve_all_instances(solver_manager, 'gurobi', subs)
Which gives an error:
Error Message
So what I am doing wrong?
Or, is it not possible to solve them in parallel?
The error message that you're seeing means that SolverManagerFactory("pyro") gave you None. It's possible that pyro isn't installed or on your PATH.
Try installing the Pyomo extras: conda install -c conda-forge pyomo.extras or pyomo install-extras

import matplotlib.pyplot gives ImportError: dlopen(...) Library not loaded libpng15.15.dylib

Importing pyplot gives an error:
In [1]: import matplotlib
In [2]: import matplotlib.pyplot as plt
ImportError Traceback (most recent call last)
<ipython-input-2-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
25
26 import matplotlib
---> 27 import matplotlib.colorbar
28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
35 import matplotlib.colors as colors
36 import matplotlib.contour as contour
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
25 import matplotlib.artist as artist
26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
28 import matplotlib.path as mpath
29 from matplotlib import _path
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
54
55 import matplotlib.tight_bbox as tight_bbox
---> 56 import matplotlib.textpath as textpath
57 from matplotlib.path import Path
58 from matplotlib.cbook import mplDeprecation
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
20 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
21 from matplotlib.ft2font import LOAD_TARGET_LIGHT
---> 22 from matplotlib.mathtext import MathTextParser
23 import matplotlib.dviread as dviread
24 from matplotlib.font_manager import FontProperties
/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py in <module>()
61
62 import matplotlib.colors as mcolors
---> 63 import matplotlib._png as _png
64 ####################
65
ImportError: dlopen(/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
Referenced from: /Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: image not found
I've looked at Error importing matplotlib.pyplot
which suggests deleting the matplotlib folder. I tried it and it didn't work. This also doesn't have a solution, but I think is related: Python: py2app "ImportError: dlopen(): Library not loaded"
Also i made sure I have libpng installed (via brew).
Thanks,
(sorry I can not comment yet.. so here's a new post)
I had the same problem when installing another library (spynner): dlopen(…) Library not loaded libpng15.15.dylib
I tried a similar method to #travelingbones's answer, and just wanted to add some notes for future readers:
DYLD_LIBRARY_PATH should contain directories, not files. E.g.,
export DYLD_LIBRARY_PATH=/Users/xxx/anaconda/lib:$DYLD_LIBRARY_PATH
and not
export DYLD_LIBRARY_PATH=/Users/xxx/anaconda/lib/libpng15.15.dylib:$DYLD_LIBRARY_PATH
The error /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20 is caused by the wrong DYLD_LIBRARY_PATH, since file path /usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib does not exist (notice the double libpng15.15.dylib in the file path).
After I had set the new DYLD_LIBRARY_PATH, I found my matplotlib was messed up, with the following error:
ImportError: dlopen(/Users/shenggao/anaconda/lib/python2.7/site-packages/matplotlib/backends/_macosx.so, 2): Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /Users/shenggao/anaconda/lib/libjpeg.8.dylib in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
To solve this problem, I changed DYLD_LIBRARY_PATH back to the old value (i.e., empty), and added the libpng path to DYLD_FALLBACK_LIBRARY_PATH
like this:
export DYLD_FALLBACK_LIBRARY_PATH=/Users/shenggao/anaconda/lib:$DYLD_FALLBACK_LIBRARY_PATH
Finally matplotlib and my new library worked like a charm!
I followed these directions and got a different error that's fixable:
First I checked what's in that path:
macair93278:~ r8t$ echo $DYLD_LIBRARY_PATH
(empty)
Next to locate the file I need (libpng15.15.dylib):
macair93278:~ r8t$ locate libpng15.15.dylib
/Applications/KeePassX.app/Contents/MacOS/libpng15.15.dylib
/Users/r8t/anaconda/lib/libpng15.15.dylib
/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib
/usr/X11/lib/libpng15.15.dylib
Now I appended the bottom three to the path and checked the path:
macair93278:~ r8t$ echo $DYLD_LIBRARY_PATH
/usr/X11/lib/libpng15.15.dylib:/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib:/Users/r8t/anaconda/lib/libpng15.15.dylib
ok, so now the test,
macair93278:~ r8t$ ipython
In [1]: import matplotlib
In [2]: from matplotlib import pyplot
…(bunch of output)
ImportError: dlopen(/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
Referenced from: /Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: no suitable image found. Did find:
/usr/X11/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
/Users/r8t/anaconda/pkgs/libpng-1.5.13-1/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
/Users/r8t/anaconda/lib/libpng15.15.dylib/libpng15.15.dylib: stat() failed with errno=20
A different error! progress!
Now following this page I ran the brew link, then unlink it didn't fix it, but it pointed me to the fact that pyplot is looking for libpng15.15.dylib in usr/local/lib but they aren' there:
macair93278:~ r8t$ cd ../usr/local/lib
macair93278:lib r8t$ ls *png*
libpng.a libpng16.16.dylib libpng16.dylib
libpng.dylib libpng16.a
So copy them in there:
macair93278:~ r8t$ cp ../anaconda/lib/*png* /usr/local/lib
macair93278:~ r8t$ cd /usr/local/lib
The test:
In [1]: import matplotlib
In [2]: from matplotlib import pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/Users/r8t/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends.
And we've reduced the problem to this (solved) one: problem w/ mac os backend

iolib import error in python

On Mac OS X Mountain Lion, I try
import numpy as np
import os
import statsmodels.api as sm
I get this error:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /Users/idf/PycharmProjects/PyAlgoTrade/GoldvsMiners.py
Traceback (most recent call last):
File "/Users/idf/PycharmProjects/PyAlgoTrade/GoldvsMiners.py", line 9, in <module>
import statsmodels.api as sm
File "/Library/Python/2.7/site-packages/statsmodels-0.0.0-py2.7-macosx-10.8-intel.egg/statsmodels/api.py", line 1, in <module>
import iolib, datasets, tools
ImportError: No module named iolib
If I add
import sys
print("=======")
print sys.path
print("=======")
I get
=======
['/Users/idf/PycharmProjects/PyAlgoTrade', '/Library/Python/2.7/site-packages/pytz-2013b-py2.7.egg', '/Library/Python/2.7/site-packages/statsmodels-0.0.0-py2.7-macosx-10.8-intel.egg', '/Library/Python/2.7/site-packages/pip-1.4-py2.7.egg', '/Users/idf/PycharmProjects/PyAlgoTrade', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']
=======
I have tried searching the net, but I am stuck on this one. Any ideas?

Resources