Convert .py to .exe with cmd - python

I was trying to convert my main.py to a exe file
I followed a tutorial on youtube i did it like it said
first open cmd in the folder
then type in pip install pyinstaller
then type in like this pyinstaller --onefile main.py
but it does'nt convert it shows this

While Eyal's solution is correct, there is an easier option. Just run this:
py -m PyInstaller --onefile main.py
It could also be python -m PyInstaller --onefile main.py depending on your system configuration.

This issue is probably caused because pyinstaller is not in the PATH environment variable.
First, find the full path of pyinstaller.exe - it should be in the Scripts directory of your Python installation (probably C:\Users\[USERNAME]\AppData\Local\Programs\Python\[Python_VER]\Scripts). Copy the full path.
Then open a command prompt (as Administrator) and run the command:
setx PATH "%PATH%;PYINSTALLER_PATH"
where PYINSTALLER_PATH is the full path of pyinstaller you have copied.
Then re-launch command prompt and run the command again.

Related

How can I run the file created with pyinstaller in ubuntu terminal?

On Windows, I can convert my python code to exe file using pyinstaller. And by running the resulting exe file, I can get the same output as in the normal code. In order to do the same on Ubuntu, I created the file with pyinstaller on Ubuntu again. But I couldn't find how to run this resulting file. Can you help with this?
For example:
After using pyinstaller on Windows, the file was created as:
example.py → example.exe
After using pyinstaller on Ubuntu, the file was created as:
example.py → example
But here I could not run the example file in any way.
In your terminal cd into the directory containing the executable. It should be in a dist/ folder.
Then run ./example If that doesn't work it just means that the execution bit isn't set on the file.
chmod +x ./example
./example

py command not working but python command is working in cmd

I have python version 3.8.0 and the .exe is added to the path but I am trying to create a django project and need to use py -m venv command to create a virtual environment but it says py is not recognized as an internal or external command, operable program or batch file.
Use:
python3 -m venv /path/to/new/virtual/environment
( more on virtualenv you will find there: https://docs.python.org/3/library/venv.html)
Since the "python" command is working, your "python.exe" was added to PATH correctly. However, the "py" command is actually using C:\Windows\py.exe to be functioned.
Therefore, you need to add
C:\Windows\
to PATH as well, to make the command "py" work as "python".

Sending a PyCharm project to someone

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.

vscode ps or cmd terminal does not open current working directory and python extinction not run working directory

ps or cmd terminal does not open current working directory
How can I do this
You have to know where the file is, and then you can copy your route to cmd and by using cd you will be in the route, then you can use py filename.py. (You need to have py installed in path) Also, you can use ctr+shift+c on vscode to open the working directory in cmd.

How to convert python script to exe Without additional files

I want to convert my python script to exe without additional files like ddl, pyd..
Is it possible?
Use pyinstaller https://github.com/pyinstaller/pyinstaller
Install it by running pip install pyinstaller in terminal / console
Then run pyinstaller --onefile yourscriptsname.py and it will create you an exe file in the same directory

Categories