I am trying to do Google's deep learning course on Udemy. For assignment one I need to verify that the following modules are working on my machine, but can't get matplotlib.pyplot working. The python code I must get to compile is the following:
# These are all the modules we'll be using later. Make sure you can import them
# before proceeding further.
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import tarfile
from IPython.display import display, Image
from scipy import ndimage
from sklearn.linear_model import LogisticRegression
from six.moves.urllib.request import urlretrieve
from six.moves import cPickle as pickle
# Config the matplotlib backend as plotting inline in IPython
%matplotlib inline
When I compile and run this like so:
python3.6 nn_assignment_1.py
I get the following error:
Traceback (most recent call last):
File "nn_assignment_1.py", line 9, in <module>
from IPython import display, Image
ImportError: cannot import name 'Image'
Any ideas how to get matplotlib working for python 3 here? I have been banging my head against the keyboard for hours trying to figure this out.
Related
I'm writing python scripts in vscode and recently I've been having a problem related to imports.
Lines of code above imports work and their output is displayed in the terminal:
print("hellow")
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
> hellow
Lines of code below the imports are not executed, but no errors are displayed in the terminal!
import matplotlib.pyplot as plt
import numpy as np
#from scipy.special import erfc
from scipy.linalg import solve
print("hellow")
>
I'm guessing there is something wrong with my vscode settings, but why are no errors showing up in the terminal?
Thanks for your help.
My python file looks like this:
import sys, os
sys.path.append("../..")
sys.path.append("..")
sys.path.append(os.getcwd())
#import pdb
from sklearn.preprocessing import StandardScaler
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
import copy
from tslib import tsUtils
from tslib.src.synthcontrol.syntheticControl import RobustSyntheticControl
from tslib.src.synthcontrol.multisyntheticControl import MultiRobustSyntheticControl
But i keep receiving this error:
Traceback (most recent call last):
File "testScriptMultiSynthControlSVDV1.1.py", line 34, in <module>
from tslib import tsUtils
ImportError: cannot import name 'tsUtils'
While the tsUtils file is clearly inside the src folder. Any idea as to why I'm getting "cannot import name" error would be extremely helpful.
dir(module) lists all members of a file/module. From the print result, it is obvious that you do not have a member called tsUtils.
Basically you are trying to import some member/attribute which is not defined in that module/file.
Ensure you are working with right version of files.
I would suggest that first uninstall tsUtils using pip uninstall command then install again using pip install and restart your system.
I tried to follow a tutorial on how to setup tensorflow gpu (https://www.youtube.com/watch?v=tPq6NIboLSc) but on the jupyter step i am getting this error :https://pastebin.com/gm3g8cC5
(ive set in in a pastebin because its very long)
I dont know what to do, ive also tried others tutorial but none of the others works, they also got errors ( but they are differents) at the jupyter step.
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
Here is the part where the errors pops.
I dont know what is my tensorflow version since when i am trying to import it i am getting OSError: [WinError 193] %1 is not a valid Win32 application
I installed the library Mouse in a virtual environment through the conda prompt, and while importing the lib.mouse library, results in an error.
import argparse
import datetime
import imutils
import time
import cv2
import numpy as np
from lib.mouse import Mouse
from lib.video_source import getVideoSource
from lib.polygon import drawQuadrilateral
from lib.user_interaction import getPerpectiveCoordinates
from lib.fgbg_calculations import getThresholdedFrame
from lib.heatmap import Heatmap
from lib.coordinate_transform import windowToFieldCoordinates
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-d5f001ef6688> in <module>
5 import cv2
6 import numpy as np
----> 7 from lib.mouse import Mouse
8 from lib.video_source import getVideoSource
9 from lib.polygon import drawQuadrilateral
ModuleNotFoundError: No module named 'lib.mouse'
I am assuming you copy your code from https://github.com/dev-labs-bg/football-stats
In the repo, there is a folder called lib. You need to copy that too. It's not part of opencv library, it's a python module from that repo.
This piece of code:
from matplotlib import pyplot as plt
always worked fine until now.
When i run every files with this piece of code, they are runned up to this code line and then the execution is stopped without error signaling.
It works as if the file ended on that line.
My matplotlib version is 1.2.0, and numpy 1.6.2.
How can i solve it?
Reinstalling the module?
UPDATE:
from __future__ import division
import os
import glob
import scipy
import numpy as np
import pymorph as pm
#import pylab as plb
#import math
import matplotlib
print("before matplot")
from matplotlib import pyplot as plt
print("after matplot")
import cv2
import mahotas as mh
from skimage import morphology
from math import sqrt
import copy
#... the others code's lines (1700 lines of code) are runned only if
#"from matplotlib import pyplot as plt" is commented
output:
>>> ================================ RESTART ================================
>>>
before matplot
>>> ================================ RESTART ================================
>>>
UPDATE 2:
import matplotlib.pyplot as plt; plt.figure(); plt.show()
from python Shell works and open a grey windows with command bar below
<matplotlib.figure.Figure object at 0x03741B70>
I was having the same issue. It looks like if you remove the .pyc file from the directory it works just fine. Check this answer out for more info https://stackoverflow.com/a/14132653/1373468