How can I solve this problem? (vs code error) - python-3.x

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import check_util.checker as checker
from IPython.display import clear_output
from PIL import Image
import os
import time
import re
from glob import glob
import shutil
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow import keras
print('tensorflow version: {}'.format(tf.__version__))
print('GPU available: {}'.format(tf.test.is_gpu_available()))
Error: Session cannot generate requests Error: Session cannot generate
requests at w.executeCodeCell
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:320068)
at w.execute
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:319389)
at w.start
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:315205)
at runMicrotasks () at processTicksAndRejections
(internal/process/task_queues.js:93:5) at async
t.CellExecutionQueue.executeQueuedCells
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:329732)
at async t.CellExecutionQueue.start
(c:\Users\ooche.vscode\extensions\ms-toolsai.jupyter-2021.8.1054968649\out\client\extension.js:90:329272)
I think this problem has something to do with kernel.
But I can't find a solution, even though I've already reinstalled and restarted.
Please help me solve this problem.
I'm using Python 3.7.10, Tensorflow 2.3

Please try again by restarting the VS code or by changing the jupyter virtual environment (Change kernel for the notebook) while executing this code in VS code.
(I tried the same code as mentioned above in VS code using python 3.7.10 and tensorflow=2.3 and it executed successfully)
Please check this output:
tensorflow version: 2.3.0
WARNING:tensorflow:From C:\Users\Hp\AppData\Local\Temp\ipykernel_6944\127915523.py:16: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
GPU available: False

Related

AttributeError: module 'numpy.random' has no attribute 'BitGenerator' in python 3.8.10

I'm trying to import the xarray module into python 3.8.10 but I get this error:
AttributeError: module 'numpy.random' has no attribute 'BitGenerator'
In order to allow you to reproduce the error: First of all, I created a new environment with conda and by importing at the same time the modules I need (to avoid the problems of incompatible dependencies) :
conda create -n Myenv Python=3.8 matplotlib numpy time xarray netCDF4 termcolor
Then, I try to import in ipython3 all modules I need to run my code:
import matplotlib as mpl
mpl.use('agg')
import numpy as np
import os
import time
import glob
import sys
from datetime import datetime,date,timedelta
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.colors as colors
# from operator import itemgetter
from netCDF4 import Dataset
from mpl_toolkits.basemap import Basemap, shiftgrid
from termcolor import colored
import xarray as xr
and, at this moment, I get the error...
I searched the documentation to see if the BitGenerator Attribute exists in my version of numpy (1.22.3), and it does. So I don't understand why this error occurs.
Someone can help me to understand please ?
Thank u !
If you want more informations about my environnement, I can provide.
I solved mine with pip install --upgrade numpy

'gensim' is not defined even though it shows in the virtualenv packages

I use virtualenv in Python. I use gensim in a script. I get this error
name 'gensim' is not defined
I tried to install genism using pip and conda. I ended up updating conda packages after some suggested solution .
I see there is genism 3.8 after reunnig pip list, but I still have the error !. Could you please tell me what to do
P.S. I take input from a html form in a Flask function. Inside the function, I call the script that has genism. The program show the forms input buttons . After clicking the submit buton, I get the error message.
import re
import numpy as np
import pandas as pd
from pprint import pprint
#database
import db
from db import *
# Gensim
import gensim
import gensim.corpora as corpora
from gensim.utils import simple_preprocess
from gensim.models import CoherenceModel
from gensim.parsing.preprocessing import preprocess_string, strip_punctuation, strip_numeric
# spacy for lemmatization
import spacy
# Plotting tools
import pyLDAvis
import pyLDAvis.gensim # don't skip this
import matplotlib.pyplot as plt
#matplotlib inline
from conn import *
from functions import *
# Enable logging for gensim - optional
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.ERROR)
import warnings
warnings.filterwarnings("ignore",category=DeprecationWarning)
Thanks in advance

Terminal Command to install imported module of a module

Lets assume I have a module say utility.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from datetime import datetime
import os
import random
import sys
import threading
import numpy as np
import tensorflow as tf
.....
I'd like to import this in my drive.py. I have it saved in my local directory and have in my first line
from . import utility
Is that possible, to issue a command in terminal to find the non-local modules ( tensorflow, numpy, etc), and install them using pip?
Any workaround would be appreciated.
CS
If you mean that you'd like the command to parse the file's imports and install missing dependancies automatically, then no it is not possible.
There are modules that are not imported with the pip's package name. For example the package facebook-sdk is imported as import facebook, making impossible to deduct the package name from the import.

while import resnet got error - ImportError: cannot import name '_obtain_input_shape''

I got an while importing resnet.
I tried removed latest version and install old version of keras==1.0.6 and it doesn't work. Also i did changes in resnet.py --> "from keras_applications.imagenet_utils import _obtain_input_shape , i got an error an like "ImportError: cannot import name 'GlobalMaxPooling2D' "
from keras.applications.imagenet_utils import _obtain_input_shape
import os
import numpy as np
from pickle import dump
import resnet
import numpy as np
from keras.preprocessing.image import load_img, img_to_array
from keras.models import Model
from os import listdir
import cv2
from keras import applications
I need import all these without an error. kindly help me to sort this. Thanks in advance
Change
from keras.applications.imagenet_utils import _obtain_input_shape
with
from keras_applications.imagenet_utils import _obtain_input_shape

TensorFlow Object Detection API - error = "This call to matplotlib.use() has no effect because the backend has already been[...]"

I'm trying to get the TensorFlow Object Detection API on Windows. I use Python 3.6.5 (64bits).
After running the following program:
Here is the part of the code which generates the warning:
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
import cv2
cap = cv2.VideoCapture("video.mp4")
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as vis_util
I have this warning message :
Warning (from warnings module):
File "C:\Users\leahj\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\utils\visualization_utils.py", line 25
import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
UserWarning:
This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
Can anybody help me please ?
The line import matplotlib; matplotlib.use('Agg') is hardcoded in object_detection\utils\visualization_utils. I don't know the reason for this; usually a package should allow the user to choose the backend.
Unless there is any other problem arising from the use of object_detection the easiest is probably to live with this warning.

Resources