I created a python script which opens some tabs and some programs and in a directory creates a folder. Now the problem is when using pyinstaller i converted this .py file into .exe file it was succesfully converted but when i ran this .exe file in virtual machine windows 7 it gives an error
The program can't start because api-ms-wncrt-runtime-I1-1-0.dll is missing.
Is there a way to include all such modules inside the .py file so that the program runs somehow
UPDATED
i used pyinstaller -w -F .py. Now i copied the exe file
only into the shared folder cuz i only want the exe file .
Following are the modules i imported in my python code
import tkinter
import input1
import input2
import random
import webbrowser as wb
from tkinter import *
import subprocess
import os So is there a way to include any library or module which will solve this issue
Did you use the -F option when using pyinstaller?
When you do:
pyinstaller -F python_file.py
It grabs all of the modules you've used to make the package (provided you have them in your envrionment I think) and makes it into one file. If it makes a separate folder for the libraries, you have to copy the folder around with the exe file or it won't work.
If this ms-wncrt-runtime is not a python module then afaik you can't add this to your python package and will need to install it on your machine separately. Hope that helps.
Related
I am trying to convert my .py file to an .exe file and I have tried all methods (auto-py-to-exe, pyinstaller, cz_freeze) and it does create the exe file but it always gives an error or the window opens and closes as soon as I double click the file.
It is a SpeechRecognition AI project coded in python. And it works just fine in the IDLE but once I create the .exe and try to run it the window pops up and shut down immediately after. (I use the cx_freeze and setup.py method for this)
If I try to convert .py to .exe using pyinstaller it gives me several different kinds of error messages.
As a .py file it works just fine but it doesn't work as an exe.
This is the error I get when using pyinstaller or auto-py-to-exe: Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception: Module 'pythoncom' isn't in frozen sys.path
Module 'pythoncom' isn't in frozen sys.path
I tried several things but nothing seems to work. I was previously using Python3.10 so I uninstalled it and downgraded to Python3.8 and reinstalled all the modules so technically it should work. I tried to create .exe files of another project and it worked just fine.
Another issue I come across is ModuleNotFoundError: No module named 'pyttsx3.drivers' I compiled the .exe using cx_freeze and it did create an .exe but it gives me this error.
Could someone please help me out with this?
(PS: This is the list of imports I am using for this project:
screenshot of all imports
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import wikipediaapi
import webbrowser
import os
import time
import subprocess
import wolframalpha
import json
import requests
from newsapi import NewsApiClient)
I just solved this for my project, which is using none of the direct imports your project is, but it appears the same low level library is causing an issue.
In my case, the single import is:
from pywinauto.application import Application
The solution is to tell PyInstaller to bundle the missing .DLL, which in this case is pythoncomxx.dll where xx is your python version. 39 in my case.
Here is the call that eventually worked for me.
pyinstaller --onefile --add-binary ".venv/Lib/site-packages/pywin32_system32/pythoncom39.dll;." autoTest.py
More generally: pyinstaller --onefile --add-binary "[path to dll];." file.py
Note, I'm on Windows. If you are on mac/linux, the ; character in the --add-binary argument would be :. See note in the documentation here
Discussion
This clicked for me when I used ProcMon to profile the file access of my initial version that was failing. It was looking for this .DLL in a bunch of different folders, then quitting.
The answers to this question were helpful. But I didn't want to settle for copying the DLL to output manually. And consequently, having to use a directory output versus a single executable file.
Answers on this question also gave the hint about using the --add-binary flag, but ultimately I had to provide the specific path to the missing DLL instead of just referencing by name as these answers showed. It probably works to specify the DLL by name if it is accessible on your PATH.
How to locate this DLL in the first place? Do a search on your site-packages folder.
I am trying to convert my .py file to an .exe file and I have tried all methods (auto-py-to-exe, pyinstaller, cz_freeze) and it does create the exe file but it always gives an error or the window opens and closes as soon as I double click the file.
It is a SpeechRecognition AI project coded in python. And it works just fine in the IDLE but once I create the .exe and try to run it the window pops up and shut down immediately after. (I use the cx_freeze and setup.py method for this)
If I try to convert .py to .exe using pyinstaller it gives me several different kinds of error messages.
As a .py file it works just fine but it doesn't work as an exe.
This is the error I get when using pyinstaller or auto-py-to-exe: Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception: Module 'pythoncom' isn't in frozen sys.path
Module 'pythoncom' isn't in frozen sys.path
I tried several things but nothing seems to work. I was previously using Python3.10 so I uninstalled it and downgraded to Python3.8 and reinstalled all the modules so technically it should work. I tried to create .exe files of another project and it worked just fine.
Another issue I come across is ModuleNotFoundError: No module named 'pyttsx3.drivers' I compiled the .exe using cx_freeze and it did create an .exe but it gives me this error.
Could someone please help me out with this?
(PS: This is the list of imports I am using for this project:
screenshot of all imports
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import wikipediaapi
import webbrowser
import os
import time
import subprocess
import wolframalpha
import json
import requests
from newsapi import NewsApiClient)
I just solved this for my project, which is using none of the direct imports your project is, but it appears the same low level library is causing an issue.
In my case, the single import is:
from pywinauto.application import Application
The solution is to tell PyInstaller to bundle the missing .DLL, which in this case is pythoncomxx.dll where xx is your python version. 39 in my case.
Here is the call that eventually worked for me.
pyinstaller --onefile --add-binary ".venv/Lib/site-packages/pywin32_system32/pythoncom39.dll;." autoTest.py
More generally: pyinstaller --onefile --add-binary "[path to dll];." file.py
Note, I'm on Windows. If you are on mac/linux, the ; character in the --add-binary argument would be :. See note in the documentation here
Discussion
This clicked for me when I used ProcMon to profile the file access of my initial version that was failing. It was looking for this .DLL in a bunch of different folders, then quitting.
The answers to this question were helpful. But I didn't want to settle for copying the DLL to output manually. And consequently, having to use a directory output versus a single executable file.
Answers on this question also gave the hint about using the --add-binary flag, but ultimately I had to provide the specific path to the missing DLL instead of just referencing by name as these answers showed. It probably works to specify the DLL by name if it is accessible on your PATH.
How to locate this DLL in the first place? Do a search on your site-packages folder.
I have this code which i need to create it as a python exe file, where in user has to click the workflow done.
My Sample Project
import os
import pandas as pd
import sys
import csv
path = os.getcwd()
v1 = pd.read_csv(r"path\V1.tsv", delimiter = '\t')
v1.to_csv(r"path\v2.csv", index=False)
I used Pyinstaller to create a .exe file but it didnt help me achieve what I want. Can some one suggest me?
Depending on what disappointed you about PyInstaller, (speed? size? too many files in directory?), you may either want to try:
PyInstaller's --onefile flag, which will compile everything into one .exe file but will take forever to run
cx_Freeze. This can generate .exe files like PyInstaller, though performance won't be much better. What I find most useful is to compile the files into an installer by calling py setup.py bdist_msi (Windows) or py setup.py bdist_dmg (Linux). People can use the installer to add the .exe to their machines. Installer-created .exe files will run very quickly.
Have your tried using the --onefile flag to specify that you only want 1 exe file to be created for that script.
For example use the cmd: pyinstaller --onefile file_name.py
If this does not help can you specify the issue that is occurring.
I was doing the same on windows with os.system("filename.exe")
But on mac, pyinstaller is creating unix executable and have no extension to it.
I've tried os.system("filename") which didn't work.
I've also tried os.system("./filename") which worked on python script but when I make executable file it is not working.
if the executable is python just import the file and it will run the main block
assume this is a.py
print('hello')
and in your python code do
import a
the output will be
hello
My program contains 3 files (2x .py and .json). I would like to make single exe file. I tried py2exe with basic setup settings:
from distutils.core import setup
import py2exe
setup(console = ['my_main_file.py'])
It doesn't work. When I run exe file from dist directory terminal window blinks for a second. I tried also pyinstller but result is similar. How can I make it?
I solved it! I launched my .exe file from terminal and received an error "there is no file myfile.json" or something like that. I simply copied this file to disc directory and program works.