Having trouble in creating exe file for python script - python

I used py2exe to make an exe of my Python script but when I run the exe file it gives me matplotlib data file missing error. What can I do for this thing?
Also I tried using pyInstaller but when everything was completed there was a run time error saying that application failed to start side by side configuration pyinstaller.
I am importing these files in my Python script:
import cv2
import numpy as np
from SimpleCV import *
import SimpleCV
import random
import time
Is there some workarounds or a proper solution I need it badly!

There are some workarounds and information for several modules on py2exe website. For matplotlib check this
import matplotlib
...
setup(
...
data_files=matplotlib.get_py2exe_datafiles(),
)

Related

Pyinstaller onefile doesn't work on other computers

My role at work includes automating several processes which are easily automated via Python, for use by the entire team at the office. None of my coworkers have Python set up on their devices (we're all Windows) nor would they be comfortable using it if they did, so I've been compiling my work into .exe files with tkinter.
My most recent (and, of course, the most important) program compiles into a onefile .exe without issue, and runs perfectly on my computer. My coworkers are able to open it and load files into it, but when they go to activate some of the tkinter buttons within, one coworker has absolutely nothing happen while another gets a windows error message that the program has crashed. I'm unable to recreate these issues on my side.
The .exe was made using pyinstaller in a virtual environment, in which I installed all necessary dependencies. The script does not need to read or reference any other files in order to run. Is it possible that the .exe is still somehow missing a dependency that it's finding on my device and not others? How can I be sure? Would setting it up to include an installer wizard make a difference? Thanks for the help on this!
I can't include the full script due to character limit, but I've included the opening lines with all imports.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.fft import fft as fft
from scipy.fft import ifft as ifft
from tkinter import *
from tkinter import ttk
from tkinter import simpledialog
from tkinter import filedialog
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

no module named sys and time

I wrote a GUI, for which I used these imports:
import os
import sys
import serial
import scipy
import string
import time
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from collections import deque
from numpy import array
from pylab import xlabel, ylabel, subplot
from scipy.fftpack import fft
from pylab import *
There is a red line below sys and time, I am using pycharm community edition 4.5.3, it is showing the reason for this error is 'no module named sys' and same for time.
But when i tried to run it, it works perfectly.
What is the reason behind it and will it affect my code in future?
Change the python interpreter from python to python2.7. It's helped me.
This is something I just ran into with Intellij 2017.3.4 where it could find every module except sys and time in the editor, but everything would run fine. I had both 2.7 and 3.5 version of python and it did not seem to matter which one I selected as the SDK. I tried adding and removing them.
When I went to Project Structure -> Platform Settings -> SDKs -> Python 3.5 -> Packages it prompted a warning that Python packaging tools not found. and had an install link. I installed it and the editor no longer complained about sys and time. When I switched SDKs to 2.7 (without installing the packaging tools) it complained again.
So I am not exactly sure what is happening that that seemed to fix it for me it other people run into this problem.

How do i convert my Python script (that has imported modules) to a windows exe?

Here are the import modules that my script uses :
import datetime
from dateutil import parser
from tkinter import filedialog
import tkinter
import mailbox
import pprint
import json
import urllib.request
from tkinter import *
#my script code here
How can i convert it into a windows exe. Im using python 3.4. People have suggested cx_freeze however there is no documentation on it therefore have no idea how to use it? Py2exe worked on a test script with no imported modules, but when i tried to compile my script, it didnt work? If my script is called test.py, what would the cx_freeze command be to covnert it?
Try www.py2exe.org/
py2exe is a nice module that you may find useful.
Or, if you are in linux/mac then you might try freeze method try https://wiki.python.org/moin/Freeze
I highly suggest PyInstaller.
I used to use it in order to create the exe file with multiple library files, then compress all these files into a self extracting archive, obtaining a fully working standalone exe file.
It doesn't require other scripts or code, you only have to create the file using "Makespec.py" and "Build.py".
If I'm not wrong, there is a new version compatible with Python 3.4...otherwise you could convert your script to Python 2.7.

scons cannot import numpy module

I have a sconstruct file and i am trying build a process.
A part of my code is below.
# Import modules needed by Scons
import os
import sys
# Create an Scons Environment
env = DefaultEnvironment()
env.Decider('MD5-timestamp')
sys.path.append(r"C:\Python27\Lib\site-packages")
sys.path.append(r"C:\Python27\Lib\site-packages\numpy")
sys.path.append(r"C:\Python27\Lib\site-packages\numpy\linalg")
import numpy
When i try to run scons, it complain about not able to find some sub module of numpy such as lapack_lite, _umath_linalg. The screenshot of the error attached.
I have checked this files inside my site-pacages. It is defintely present inside the folder.
When i import numpy library from python, i dont have any problem.
I had a dependency issue.
The only solution that worked was to completely remove python, all its libraries.
Reinstall python, libraries and scons back. Made sure all pythonpath and sys path are set properly.
It started to work

Building wxpython exe using PyInstaller

I am trying to build an exe using PyInstaller (with Python 2.7) and have been stumped. My python code uses the modules wx, matplotlib, basemap (a part of matplotlib), and pylab. There are others, but these seem to be the main ones.
I have installed PyInstaller and then i did:
python pyinstaller.py C:/Python27/Convertthisfile.py
It goes through the whole process, but when i try to run the final executable, it comes up with the error:
"No module named PyQt4.QtCore"
I have installed PyQt GPL 4.9.1 for Python 2.7. However, I have no idea where PyQt is even being used in my code. I don't specify it anywhere that i know of.
Anyone have any thoughts? Nothing I do seems to work. I have even tried the GUI2EXE.py -- i can't get py2exe, pyinstaller, or cx_freeze to work.
HELP!
I have added my code below to hopefully help. To answer the comments, yes, my code is located in C:\Python27. I have no problem "building" it with pyinstaller, but the above error comes up when i try to run the given executable. I have searched the code and do not see any use of PyQt4.
When i run cx_freeze, i have issues with the basemap data files -- they do not seem to be included in the ".zip" when i build it. Also, none of my modules seem to get included either.
Here is what i import for my code (some of these functions are my own -- mainly the last ones listed).
import wx
import time
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
from datetime import datetime
import wx.calendar as cal
import wx.lib.mixins.listctrl as listmix
from pylab import *
from decimal import *
import adodbapi
import annote_new
import cPickle as pickle
import calc_dist
import Game_Score
import Calculate_Distance
import Duplicate_Finder
import copy
Hopefully this clears things up?

Categories