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.
import numpy as np
import pandas as pd
import cv2
from matplotlib import pyplot as plt
from pylab import imread
from skimage.color import rgb2gray
from PIL import Image
from skimage import feature
I reinstalled Windows 10, so I had to reinstall Anaconda and Jupyter also.
I usually use these import statements, however, now I'm getting an error:
ImportError: cannot import name 'imread' from 'pylab'
(C:\Users\DELL\Anaconda3\lib\site-packages\pylab__init__.py)
Do you have any suggestions? I have installed Pylab, PIL and Matplotlib already.
Try to add:
from matplotlib.pyplot import imread
in stead of:
from pylab import imread
Getting this error message:
MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
How do I put in place the mpl_finance package instead. I have it installed in pip, but what is the proper import phraseology?
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
from matplotlib.finance import candlestick_ohlc
import matplotlib.dates as mdates
import pandas as pd
import pandas_datareader.data as web
from googlefinance import getQuotes
import json
from datetime import datetime
from forex_python.converter import CurrencyRates
from yahoo_finance import Share
All code for matplotlib.finance moved to a separate repository. Here is an example of usage. To answer your question:
from mpl_finance import candlestick_ohlc
To import a module which is installed through pip with the name x you would mostly want to do import x.
So, here
import mpl_finance
or to get one of its functions, e.g.
from mpl_finance import candlestick_ohlc
new version can be found here: https://pypi.org/project/mplfinance/
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.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Outputed py2exe exe won't run only when signed: ImportError
I asked a similar question previously (Creating executable with Py2exe and matplotlib errors) that dealt with matplotlib errors. However, I have gotten past this stage. Now when I try to build my executable, none of my packages/code seem to import. For example, my code imports the following:
import os
import csv
import wx
import time
import math
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
I get a log error when I run my executable that it "No Module Named os". I get an error for every module I have in my code (if i change the order in which things are imported). Why aren't any of my modules importing? My Py2exe code looks like:
import os
from distutils.core import setup
import py2exe
from distutils.filelist import findall
import matplotlib
import glob
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle
import wx
setup(
windows=[{'script': r'Scout_Tool.py'}],
data_files = [(r'mpl-data', glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\*.*')),
(r'mpl-data', [r'C:\Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
(r'mpl-data\images',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl- data\images\*.*')),
(r'mpl-data\fonts',glob.glob(r'C:\Python27\Lib\site-packages\matplotlib\mpl- data\fonts\*.*'))],
#matplotlib.get_py2exe_datafiles(),
options={
'py2exe':{
'includes': [
'matplotlib',
'matplotlib.backends.backend_wx',
'matplotlib.pyplot',
'mpl_toolkits.basemap',
'matplotlib.figure',
'numpy.random',
'wx.calendar',
'mpl_toolkits',
'numpy',
'datetime',
'wx',
'pylab',
'adodbapi',
'sqlparse',
'annote_new',
'cPickle',
'pylab'
],
'dll_excludes': ['MSVCP90.dll'],
}
},
)
Any thoughts on why my modules aren't importing after I run the py2exe? BTW, I get no errors when running the py2exe code -- only when i try to run the produced executable. Thanks!
EDIT
Okay, here is what i have done. I have taken out some of the modules that I weren't using and removed the duplicates. I also fixey my setup.py file to look like:
from distutils.core import setup
import py2exe
import matplotlib
import glob
setup(
windows=[{'script': r'Scout_Tool.py'}],
data_files = matplotlib.get_py2exe_datafiles(),
options={
'py2exe':{
'includes': [
'matplotlib',
'matplotlib.backends.backend_wx',
'matplotlib.pyplot',
'mpl_toolkits.basemap',
'matplotlib.figure',
'wx.calendar',
'mpl_toolkits',
'datetime',
'wx',
'adodbapi',
'sqlparse',
'annote_new',
'cPickle',
'pylab'
],
}
},
)
After this, I cleared out my entire 'dist' folder to be sure anything wasn't kept from before. Then I ran the following in CMD Prompt: C:\Python27\python setup.py py2exe. This ran with no errors.
Then when i go to run Scout_Tool.exe, I first get a MatPlotLib data error. I am not sure why i am getting this, but to fix it, I do the following: I unzip "library.zip", then add the "data" folder from Mpl-toolkits - basemap - data, then re-zip the library folder.
Then, when I try running Scout_Tool.exe, it comes up with the error that "No module named os" exists. This is true if I put any module first in my Scout_Tool.py code.
Hopefully this helps with where i am at? Thanks!
I compiled your program (the imports) and it runs OK for me.
the py2exe missed module report is not relevant if you are not using those modules (I got the same list as that you show).
Remember that the executable will run while you execute it within the dist module py2exe creates (and not from a copy in your desktop, for example. For that you need to make a direct access link).
Not going to take credit for this but do either of these help your problem?
http://www.python-forum.org/pythonforum/viewtopic.php?f=3&t=6659
Outputed py2exe exe won't run only when signed: ImportError
This question is also a continuation of
py2exe doesn't import the os module?