I am very new to programming. I am trying to create a desktop icon that, when clicked on, will run my Python script on Mac OS.
The first line of my code involves input from the user. How can I create a desktop icon of my Python script, that when clicked, allows the user to enter the input in order to cause the Python script to start?
I have tried Pyinstaller; however, when I enter:
pyinstaller "myprogram".py
into the Mac terminal, I receive a "dist" file that includes Python script with an ".exe" file extension. However, when I click on this extension, I receive this response in the terminal window:
logout
Saving session...
...copying shared history...
...saving history...truncating history
files...
...completed.
I would like the Python script to run in order to have a user type their input in order to have the program run. Any help would be greatly appreciated.
Pyinstaller detects the OS and the version you make is only compatible with the system you build it on, they mention that on their page, so it shouldn't be building an .exe; whenever I use pyinstaller on my mac the dist has a .app and a unix executable, you don't have both of those files in there?
also, I just notices your syntax, you should not have the filename in quotations
try:
pyinstaller --clean --windowed --onefile yourapp.py
in your terminal from the directory that has your app. First delete the old folders and .spec it created the first time as well.
Also, I just went through a bundle of issues in a similar vein. If the problem persists after you delete and rerun pyinstaller with proper syntax, check out this page, I have a rather large answer all the way at the bottom, and there are other angles on the same issue there as well.
https://github.com/pyinstaller/pyinstaller/issues/3820
I am working on python project, where at particular time (8 pm) a random number will be displayed. I have converted .py file to .exe using pyinstaller. Now, I want my .exe file to run automatically and display the number, even if I won't open .exe file at 8pm.
Since you're referring to .exe I assume you're on Windows.
You should use the Task Scheduler in Windows to schedule your application to run.
For that you could run it with full path to your python.exe with the .py file as parameter, so conferting to .exe isn't really necessary.
To automagically run this on time when the system is switched off, you will need to check the BIOS settings of your PC at startup to see if you can make the computer switch on all by itself at a certain time. Make sure to set this automatic power on a few minutes before the scheduled task to allow Windows to start up first.
I am trying to run a python script, .py in the windows command prompt.
I drag the script from my files into the command prompt window. I run it.
Then, the script presents a prompt for me to enter the file I would like to parse. I am supposed to enter a file like this: filename.txt
When I go to do this, I get the FileNotFoundError. They are both located in my downloads folder. Any ideas as to why? I've tried a couple of things but having no luck.
The script must be performed this way because this is a script many people will use and it is likely that they will receive it and download it and the file to parse to their computer so it'll be located in their downloads folder.
When I created the script I did it in Notepad++ and had a separate folder where I put the file and script and it worked fine this way. I am just ensuring it works from the perspective of someone who's downloading it off an email or website, etc.
Thanks !
Yeah that happened to me a lot.
To solve it just write the whole directory of the file.
If you are in windows
c:\user\username\Desktop\file.txt
If you are in linux or mac:
/home/username/Desktop/file.txt
I am developing a key-logger on Python (only for curiosity sake). And the script will be an executable. The process will not need a UI or user interaction.
Is there any way, even in another executable to make the key-logger start at start-up?
I don't use Windows, but you can try making a batch script that runs your python file and make that script Run a program automatically when Windows starts:
Click the Start button Picture of the Start button , click All
Programs, right-click the Startup folder, and then click Open.
Open the location that contains the item you want to create a shortcut
to.
Right-click the item, and then click Create Shortcut. The new
shortcut appears in the same location as the original item.
Drag the shortcut into the Startup folder.
As I said, I don't use Windows, so it might be totally wrong.
You can refer here for making the BAT file, which basically says:
#echo off
python c:\somescript.py %*
pause
I think that the above answers are too complex. What I did was just drag and drop or copy and paste my file in the startup folder by clicking the quick access toolbar, typing "startup", and the job is done.
I am using Windows 10 operating system, so it might be different in your case.
I hope this is useful.
Edit: The key to this solution is to have the .py extension files open by default by the python console (not a text editor), otherwise it will just open the file instead of executing it. In order to select the default program a type of file is opened with, right click on the .py file -> Open with -> Choose default program. See this example:
Use VBScript:
1-> create anyname.vbs with this data:
Set wvbs=CreateObject("Wscript.Shell")
wvbs.run "full location of your File",0
2-> copy anyname.vbs file in C:\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup this folder
Now when windows start it will run your file in hidden mode
Open run with "Start + R", then open "shell:startup". it opens you a folder(the folder that was mentioned before at start menu), and every file that is on this folder, well run at startup.
The folder path is: "C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" (you can copy it on windows explorer, or copy this path and put your account name on USERNAME)
this is the trick i used in my script:
from os import getcwd
from shutil import copy
copy(getcwd()+'/FILE_NAME.exe','C:/Users/USERNAME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup')
They are some ways for file name as well, but im not familiar with it. this code copies it self to startup folder and starts each time windows boots
Create a shortcut in the shell:startup folder with an absolute path to your pythonw.exe executable. The w version of Python is needed so that it starts up without a shell in the background.
Detailed instructions
Open the startup folder
Type the Windows and R keys at the same time. In the Run dialog, type shell:startup and it enter. This takes you to the Startup folder. Shorcuts in this folder are launched when the computer starts. (For me, the startup folder is at C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.)
Create new shortcut
Right-click in this folder and say "New shortcut." Browse to "This PC," "Windows (C:)," "Program Files,", "Python39", and select pythonw.exe. Your Python install is likely in a different location. More recently, Python is found somewhere within %appdata%. (You can paste %appdata% into the run dialog to open this folder and look for Python. It opens in Roaming by default, but be sure to look in Local, too.)
As mentioned at the start of this answer, it is important that you select pythonw.exe rather than python.exe as pythonw.exe will run without opening a command prompt.
On the next "Create Shortcut" screen, titled, "What would you like to name the shortcut," you can name it whatever you want. For the OP, I recommend "Self penetration test."
Click "Finish."
Edit the shortcut to launch your script
In the Startup folder, right click on the app you just created and select "Properties."
In the Properties dialog's Shortcut tab, edit the "Target" to look something like "C:\Program Files\Python310\pythonw.exe" pentest_keylogger.py and the "Start in" to be the folder in which pentest_keylogger.py is found. (As above, you will need to use your Python distribution's path.)
Test your script
Hit OK. Then double-click on the icon to see if it works silently as you desire.
Finally, reboot your machine and use resmon (from the run dialog) or Ctl-Alt-Delete and the task manager to see if your app is running in the background.
Acknowledgements
Thanks to Eryk Sun and Behfar baghery for the core ideas presented here.
I have a python program that is executable and I can run it on my terminal by typing: ./python_file_name
This is fine for my use, but I want the program to be accessible to non-computer people. I would like to be able to create a desktop shortcut that runs the UNIX executable file. Currently when I double click the executable file it just opens the python program in a text editor. I want to be able to have the end-user double click the file so that it executes in the background.
Just for completeness, the script generates a time-sensitive-data-scraping csv file in the user's downloads folder. Therefore, there is no need to create an application with a GUI or anything fancy like that. Also, I am using Ubuntu and the end-user will be on Mac OS X.
I think you're looking for py2app. It will allow you to send your user a nice little application bundle.