B-Abbasi
B-Abbasi

Reputation: 823

Building an executable file for python code using py2exe

I installed "py2exe" for "Python2.7" , made a "Hello World" program, used py2exe to build its exe and it worked perfectly.

Now when I tried building the exe of my actual code, the folders get created and exe is also created without any problem but when I launch the exe the console appears for less than a second and closes.

Only difference in this case and test program is that I have multiple code files in this case and in some of them I am importing a few files/libraries as well Following are import commands spread across different files:

from bs4 import BeautifulSoup
import time
import requests
from RdWrtCls import *
import os
import openpyxl 

Initially my source code was :

from distutils.core import setup
import py2exe
from glob import glob
setup (console =['Crawler.py'])

when this didn't work I did some research and found that sometimes there is a missing dll problem, so I modified my code to this:

from distutils.core import setup
import py2exe
from glob import glob
data_files = [("Microsoft.VC100.CRT", glob(r'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\redist\\x86\\Microsoft.VC100.CRT\\*.*'))]

setup(data_files =data_files,console =['Crawler.py'])

I am stuck in this problem so any and all sorts of help would be highly appreciated.

Other Information: I am using: Windows7, Python 2.7-32 bit

Update : I found a suggestion in a question on stack overflow for a similar problem suggesting to run the EXE through command prompt. I ran the program through command prompt and showed me the error

Import error : No module named bs4

Upvotes: 4

Views: 1433

Answers (2)

Blaine
Blaine

Reputation: 122

My project also failed at jdcal. I was successful in just the last steps of B-Abbasi:

6) Uninstalled openpyxl using pip
(on Win7: pythonXX\Scripts\pip uninstall openpyxl)

7) Uninstalled jdcal using pip

8) reinstalled openpyxl using pip (it automatically installed jdcal )

9) Now exe runs perfectly.

Upvotes: 1

B-Abbasi
B-Abbasi

Reputation: 823

I was able to successfully build a working exe. Following are the steps I took I hope they prove helpful for others facing these issues in future.

1) Launch the program Using Command Prompt so I can view errors.

2) Put all my code(functions,classes) in main file.

3) reinstalled latest version of pip

4) Uninstalled and reinstalled BeautifulSoup4 using pip

pip uninstall BeautifulSoup4
pip install  BeautifulSoup4

5) Now "jdcal" started giving problems (it is installed when installing openpyxl)

6) Uninstalled openpyxl using pip

7) Uninstalled jdcal using pip

8) reinstalled openpyxl using pip (it automatically installed jdcal )

9) Now exe runs perfectly.

Upvotes: 3

Related Questions