I'm somewhat new to python, so it would be nice if this was explained simply, if you can.
I'm trying to make a py file (main.py) into a exe file. I've followed this tutorial (https://www.geeksforgeeks.org/convert-python-script-to-exe-file/) as well as a youtube one, which did the same thing. My project has several modules. The conversion works, but if I try to open it, it tells me: (ModuleNotFoundError: No module named 'requests'). I would assume it does this for the rest of them if it gets the chance to. I don't know how to fix this and it would be nice if I could have a exe file so I could share programs with friends that don't have python installed. (I'm using pyinstaller for the process, same as the tutorial)
requests is a 3rd party library. I assume when you created the .exe, you did not "assembled" together your script with its dependencies.
According to the linked tutorial, you should check the pyinstaller's config and try to give pyinstaller the missing packages and somehow compile it with them, e.g.
For any missing package:
pyinstaller --hidden-import 'package_name' --onefile 'filename.py'
Just install requests:
pip install requests
Then you'll be able to bundle the script into an exe, provided there aren't any other missing dependencies.
According to your question either the requests module isn't installed or pyinstaller can't find the module!
If module isn't Installed then open up your terminal/Command Prompt and execute the follow command:
pip install requests
But if module is installed then what you can do is manually specify Pyinstaller which module to include also
so to compile it to exe use this command
pyinstaller --hidden-import 'requests' --onefile 'main.py'
Here the option --hidden-import means it will import the module requests also and --onefile means it you will get a single Exe file which will contain everything
Note! if you use --onefile this can effect your time taken to start your program!
Thanks
Edit:
According to the tutorial it shows you to open "PowerShell" but I recommend you to use "CMD" for this purpose!
Related
I am trying to compile a python script into an executable using pyinstaller --onefile. However, one necessary package, geemap, doesn't seem to be included, despite being an import in the script.
Is it possible to force-add custom packages?
Every time I run the .pyc file on a clean PC, it says:
ModuleNotFoundError: No Module named 'geemap'
You could try:
pyinstaller --onefile --hidden-import=geemap
This should force-add the package.
I just finished working on a PyCharm project (using python 3.7), which uses libraries downloaded using PyCharm's built in functionality. I just want to send this project to my boss so that he can simply run it by clicking on it, without having to go through downloading PyCharm and downloading the applicable packages. Please tell me that there is a way to do this. Thank you
if you want to convert your python project to a program exucutable in windows you can use the library pyinstaller.
install the library:
pip install pyinstaller
then in the path of the project,open a command console and type the following commands.
if you want the executable in one file(slower start):
pyinstaller.exe --onefile --windowed --icon="your_icon_file".ico "your_python_script".py
if you want the executable in one folder(faster start):
pyinstaller.exe --onedir --windowed --icon="your_icon_file".ico "your_python_script".py
this wil create a folder call "dist" where your .exe will be,
pd: whith the --onedir command you will see all your dependencies in that folder, if you have a simple script you can use the first option.
Link to the pyinstaller documentation:https://pypi.org/project/pyinstaller/
You could solve this issue by converting the .py file to an executable file or .exe file....
Hopefully it helped..thx
A simple way to that would be sharing it on github with a requirements.txt file containing all the dependencies which then can be installed using python -m pip install -r requirements.txt.
Or You can use pyinstaller --onefile <yourfile.py> to create a .exe file which could be run without any requirements on windows.
I converted the py script to exe using pyinstaller but when I try to run the exe I got this. How can I fix it?
You have to tell pyinstaller what modules it need to bundle in the program, so, in your case, you have to pass as hidden import this: pkg_resources
In the .spec file that generated after running the pyinstaller, you will find an option like this:
hiddenimports=[]
Put it like this:
hiddenimports=["pkg_resources"]
Then, run pyinstaller like this:
pyinstaller app.spec
Or, if you still want to run it trought the .py, pass it as parameter like
pyinstaller app.py --hidden-import pkg_resources
Normally, if your program its more than a "Hello world", this is going to be a few more modules, you just need to add them all to hiddenimports as a list until there is no more ModuleNotFoundError.
Remember to NOT run pyinstaller to the .py file if you modified the .spec file, as it will create a new one and overwrite it, ignoring the previous.
You have to execute pyinstaller with the .spec file
Answer provided by Sebastian which is passing the module to hidden import do solve the problem too. I happen to found another solution while waiting for the answers, just have to reinstall pyinstaller which I pip install pyinstaller initially
To uninstall the pyinstaller:
pip uninstall pyinstaller
To install pyinstaller again:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
I have developed a tkinter application but I need other users (with Windows 10 OS) to use it. Some have a python interpreter installed but others don't. I tried to create an executable through py2exe and auto py-to-exe but none worked. I also tried to run the tkinter through pythonanywhere.com but it also didn't work.
Is there a simply way to share the py files? Perhaps is there a click-to-run environment? What I don't need is to request users to install a full python application such as anaconda or WinPython, as this does not make sense for the users without a python interpreter.
I would use pyinstaller
run cmd.exe as Administartor and type:
pip install pyinstaller
then run with:
pyinstaller --onefile --noconsole --name your_script.py
This creates a single file executable which also includes your Python with all dependencies of your script/project.
If your projects contains external files like images/sounds you might need to edit the spec file as described here.
Full credit to the kid who made this video, it helped me out a lot when I had the same style of problem as you.
https://www.youtube.com/watch?v=pzc4vYqbruk
You'll just have to go through the generated .zip file to find the generated .exe file.
How I transform my program into an executable (.exe)? It has 3 .py files and images.
Made with tkinter and python 3.7, I saw that people used py2exe or pyinstaller but I don't know how to do that.
I use py2exe but options like cx_freeze and pyinstaller are also out there. What goes for mac i beleive there exist a module called py2app ;)
to use py2exe you must first have python 3.4 since it hasnt't recently been updated. After that you need to make a file in which you write
from distutils.core import setup
import py2exe
setup(windows=["yourfile"])
then you need to run the file with the following command - i called the file setup.txt here.
py -3.4 setup.txt install
remember to write .py if you used a python file and then you just need one more step
py -3.4 setup.txt py2exe
and ofcause remeber you need to have py2exe installed. If you haven't before you do anything write in to the comandoprompt
pip install py2exe
The exe will then be found i the dist folder.
imported libraries are always triggy though i think i remember that last time i had to convert tkinter to .exe i had to use cx_freeze.