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?
Related
I have an error which's complete form is
MatplotlibDeprecationWarning: The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3
I converted my script into executable file. After conversion, it never opened. When I execute script with IDEs(VS Code, Linux shell, and Spyder), it works. Somehow it does not open after I converted it to exe. I wrote some lines to avoid from this error, but simply it did not work. For example;
Python/matplotlib : getting rid of matplotlib.mpl warning
I used pyinstaller and auto-py-to-exe to convert my script into exe.
This is the beginning of my code:
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QDate, pyqtSlot
from PyQt5.QtGui import QIcon
from datetime import datetime
import calendar
import sys
import numpy as np
import pandas as pd
from scipy.signal import find_peaks
import os
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.dates as mdates
matplotlib.use('Qt5Agg')
myFmt = mdates.DateFormatter('%d')
It is very long to put all the code here. Thank you very much for your interest.
Arda, I've found out after trial and error that pyinstaller has a conflict with the latest version of matplotlib. In order to produce an executable of your script with pyinstaller you should downgrade matplotlib to 3.2.2 version. I have also found some problems with the latest (1.19.4) version of numpy which went away when I downgraded numpy to 1.19.3.
You can check my repository
https://github.com/matiasleoni/COVID19_plotter
where I created a simple script to plot COVID19 global data using matplotlib package. After many failed attempts I was also able to create an executable version of it as I described above (see also the README.md of that repository).
I've been trying for a few days to freeze a Python program. I've tried py2app, PyInstaller and cx_freeze. Of all 3, cx_freeze seemed to be the most effective.
py2app and PyInstaller seems to skip all my imports whichever settings I'm using. The modules needed are always found in "Modules not found (unconditional imports)" with py2app. With PyInstaller, everything seems to run fine, but the program fails to launch due to the fact that no modules is imported, even when specified as hidden import.
For cx_freeze, some imports seems to be done, as it is at least trying to import PyQt5.
But cx_freeze failed at this step with this error:
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/QtCore.framework/Versions/5/QtCore'
For information:
Python version: 3.7.2, installed with Anaconda3.
List of imports:
import sys
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from PyQt5 import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
OS used: MacOS 10.11.16
Targeted OS for freezing: MacOS (various versions)
At this point, I don't really know what to do to freeze my programe. If anyone has an idea, that would be awesome.
I have been working on developing a GUI application using tkinter which is 100% working properly when running it from pycharm... and now I can't convert my script into an EXE file.
I have tried pyinstaller, cxfreeze and py2exe but everyone of them has a problem. pyinstaller show me 'Fatal error'... and cxfreeze seems to have a problem with MATPLOTLIB
Here are the libraries I am using:
import numpy as np
import tkinter
from random import randint
from tkinter import *
import tkinter as tk
from math import sqrt
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from math import sqrt
from scipy import stats
from scipy.stats import beta
I don't want to post my code due to confidientality issues...
Does anybody has another idea ot do this ?
EDIT:
I reinstalled python as admin and reinstalled pyintaller
enter image description here
and when I tried to convert the script here is the command error it shows:
'pyinstaller' is not recongnized as an internal command or external ...
also I need to mention that the exe file of pyintaller in not founded in the directory of installation of python in C:programfiles/python37
I'm a relatively inexperienced programmer and I ran these import statements last week on my computer without a problem but now this week when I run the following statements in particular the wkhtmltopdf import I run into an error.
import pyodbc
import pymysql
import numpy as np
import pandas as pd
import datetime
import jinja2
import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf
import datetime
import calendar
from pathlib import Path
This leads to this error
enter image description here
Any help is appreciated
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.