Python - drag file into .exe to run script - python

I have a Python script that takes the directory path of a text file and converts it into an excel file. Currently I have it running as a console application (compiled with py2exe) and prompts the user for the directory path through raw_input().
How do i make it such that I can drag & drop my text file directly into the .exe of the python script?

The dropped file will be available as an element of sys.argv.

Related

when my exe file is executed so a copy of my exe file goes to a specific drive my my pc

When i exexute my python script .exe file, I want its shortcut or copy to go to a specific path of my drive using python code
I think that piece code should be like
def become_persistent():
copied_file_location = os.environ["location"] + "\\ my scripts.exe"
if not os.path.exists(copied_file_location):
shutil.copyfile(sys.executable, copied_file_location)
Assumming you are using PyInstaller for making your script binary, here is how you determine path to exe file
Determining application path in a Python EXE generated by pyInstaller
The rest is simple - just copy that file to the directory you'd like to.

Pyinstaller - Hide and Run Executable file through .bat file

I am trying to add one executable (.exe) file, a .conf file and a .bat file into the binary package created by pyinstaller and then through that binary package i want to call the .bat file that will send some commands to .exe and that exe will pick the configuration file from .conf and do its work.
** Example **
Click on Run button from Python Package.
Python Package runs .bat file inside it.
.bat file calls .exe with arguments
.exe picks config from .conf file and do its work
Before you create the binary through pyinstaller:
Add files (.conf and .bat and .exe) to the bundle using the Analysis call in the .spec file.
When you run the binary created through pyinstaller it unpacks itself at a temporary location in AppData on Windows by default. You should be able to get that path through sys._MEIPASS
In the python script run the .conf, .bat and .exe files preferably using subprocess.

How to convert .py script and .ui file with images to .exe

I wrote a program in Python that includes external files, including images and a GUI .ui file.
I want to convert the Python script to a single executable (.exe) file using PyInstaller. When I try to open the .exe file, the program does not open.
You will need more information on why the application is closing immediately in order to solve your problem. To view the error messages associated with running your executable, run the .exe file from the command prompt: /path/to/app/dist/MyApp.exe. This will allow you to observe any errors that may exist after the app was bundled. If the program fails during an import statement, you may need to add a package to the hiddenimports list in the .spec file. Check the PyInstaller documentation for instructions on modifying the .spec file.

Desktop Launcher for Python Script Starts Program in Wrong Path

I can not launch a python script from a .desktop launcher created on Linux Mint 17.1 Cinnamon.
The problem is that the script will be launched in the wrong path - namely the home folder instead of the directory it is placed in. Thereby it can not find other vital files accompanying it in its folder and hence does not work.
To examine that misbehaviour I created a short script to check the folder a python script is executing in:
#!/usr/bin/env python
import subprocess
import time
subprocess.call(["pwd"], shell=True)
time.sleep(7) # to get a chance to read the output
Executing it from its own folder gives the output:
/home/myusername/PythonProjects
I am setting a desktop launcher via Nemo's menu. Now executing the same script yields:
/home/myusername
I do not understand this behaviour. How could I create a working desktop launcher for my python script?
The page describes the format of .desktop files.
You may note the "Path" element, which specifies the working directory for the file to be run in. In your case you would want a desktop file that specified
Path=/home/myusername/PythonProjects
If Nemo doesn't allow you to set the Path element you may need to edit the desktop file by hand. The .desktop files are text files and you can probably find them in /home/myusername/.local/share/applications/

Making a Shortcut for Running Python Files in a Folder with CMD.exe

To run Python files (.py) with Windows CMD.exe, I SHIFT + Right Click on my project folder which contains all of my Python code files. Doing this shows a menu containing the option Open command window here, which I click to open CMD.exe with the prompt C:\Users\Name\FolderLocation\ProjectFolder>. I then type the python command, and the file I want to run in my project folder (python MyFile.py) which runs the file, of course.
What I would like to know is if there is a way I can setup a shortcut to open CMD.exe with my project folder opened/ being accessed so then all I have to do is type python and the file name? Thanks
Create a shortcut to cmd.exe.
Get properties on that shortcut, and there's an entry for the current working directory. (They change the name of that field every other version of Windows, but I believe most recently it's called "Start In:".) Just set that to C:\Users\Name\FolderLocation\ProjectFolder.
Now, when you double-click that shortcut, it'll open a cmd.exe window, in your project directory.

Categories

Resources