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

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

Related

Convert .py to .exe with cmd

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.

Execute pytest via pyinstaller created exe extension file

I had made more than 1 pytest test files I needed it to be convert them to a single exe file
I used pyinstaller for that not able to convert the test cases to .exe file
Even though if some how I will convert it I could not run it via clicking on .exe file as on console I am running it by python -m pytest
So Please help me guys
Create a bat file rather, if you want to run it on a windows environment.
Keep the required libraries ( like pytest, selenium.. etc) in a requirements.txt file in root directory.
Keep the bat file with the root directory.
The commands in the bat file will go as below.
cd path/to/current/directory &
virtualenv env &
"cmd.exe" "\c .env/Scripts/Activte && pip install -r
requirements.txt && pytes your commands to trigger script
here"
Once you hit the bat the dependent Libraries will be installed and later your scripts will trigger
Is there any way to execute the exe file created by pyinstaller, that like on just clicking the exe file the exe will get execute based on the code mentioned just like on clicking the exe file the code should execute via python -m pytest

How to build a package for Tkinter like exe in window?

In windows, we can use pyinstaller to build python code like Tkinter to an exe file for user use, How to in Linux, I don't like user to do it in terminal to run the code, Any advice? Thanks,
Linux comes with Python preinstalled, so on Linux you can just prepend a shebang #! line with the path to the interpreter to a Python script and then set the executable bit +x on the file with chmod. Then you can run it by name or click on it in the file explorer application.
If you need more than one file, you can use the zipapp module to group a folder together into a single executable .pyz archive with the shebang.

Not able to run Pyinstaller executable on Linux

I am trying out pyinstaller for the first time. I created a file named hello.py with just one line of code:
print "hello"
I used the following command to make a binary:
pyinstaller hello.py
The process completed successfully and a binary was created at dist/hello. I am not able to run this binary file. When I tried to run it from the terminal, I got,
bash: .: hello: cannot execute binary file
I tried to double click it from nautilus but nothing is happening.
How can I run this binary file?
I am using Ubuntu 16.04
Got it running by typing the relative path dist/hello in terminal
for linux (tested on ubuntu 16.04 python3)
pyinstaller hello.py --onefile it create one file named hello.
Then go inside dist folder use terminal
cd dist.
Then
./hello.
Looks not as windows way , but work. ./hello is something like , run outside...

Cannot get python on mac osx to reference my scripts folder

Am pretty new to python although have programmed a lot before. I'm using mac osx snow leopard and python 2.6.1.
I've followed this post about setting your PYTHONPATH to a custom scripts directory but can't get python to recognise it.
How can I run my python script from the terminal in Mac OS X without having to type the full path?
So i've got a simple helloworld script in /Users/richn/Documents/scripts/ called hello.py
Inside is this
#!/usr/bin/env python
print "Hello World!"
I've created a .profile file in my home directory with this in it
export PYTHONPATH=/Users/richn/Documents/scripts
I've also changed permissions of the file to make it executable with chmod a+x hello.py
Running ./hello.py in the terminal from that scripts folder works fine however whenever i run it outside of that folder i get this error
-bash: ./hello.py: No such file or directory
How can i get my scripts to run outside of that folder? Anyone got any ideas?
Thanks very much
What you'll want to do is to edit your PATH variable which is a list of directories your command shell checks when you run a command that does not begin with / or ./ rather than PYTHONPATH:
export PATH="$PATH:/Users/richn/Documents/scripts"
After you have exported your PATH variable you should be able to confirm that it has exported correctly:
echo $PATH
and afterwards you should be able to run "hello.py" successfully.

Categories