I created an executable with pyinstaller. The file is in the directory Build and I need to have several shortcuts of this .exe in many different directories. The problem is, my program uses an Excel table which will be accessed through a relative path. So when I use a shortcut of my .exe, the Excel table can't be found because the relative path works for the original .exe but not for the shortcut.
How can I access the Excel table?
Related
Problem definition:
I am running python scripts from Excel using xlwings and I have a file that I am using in these scripts.
I used to have the path specific to my computer (ex--> C:\users\myuser\some_folder\myfile).
now I am sending these scripts to my collogues to use, and I want the path of the file to be automatically configured according to the location of the file on their machines. I tried using os package.
I tried this post and this post and finally tried moving the file in the same location and used os.getcwd() to get the working directory and concatenated with the file name to get the path.
these methods worked fine when I am running the python scripts alone (not from Excel), but When I tried running from Excel it did not work because for some reason when running python scripts from Excel the working directory changes to C:\\ProgramData\\Anaconda3\\
and no longer sees the file. also, these method (according to my understanding) uses the path of the directory from which the file is running.
they are only seeing files in C:\\ProgramData\\Anaconda3\\.
my 1st thought was to try to search for the folder name using this solution but the problem is that I do not know which location the end user will store the folder in.
What I am thinking now is find a way to locate (form this location C:\\ProgramData\\Anaconda3\\ (where python is run from Excel)) the folder which the file is stored at and from there easily grab the file path. after searching the web I did not find a suitable solution for my case.
so, is there a way to do this using os or any other package?
__file__ contains the absolute path to the executed python script without being effected by the current working directory
# example script located at /usr/bin/foo.py
print(__file__)
output:
/usr/bin/foo.py
I am using an executable file generated with Pyinstaller from my Python script.
Every time I open it, it creates a folder named (for example) _MEI12345 in \AppData\Local\Temp.
How can I prevent the creation of that folder? Are there other (better) ways to create an executable file if I have to distribute it?
I have proceeded to generate an executable file using pyinstaller, once it has finished the corresponding files are generated, then:
In my windows console I apply this command: pyinstaller --onefile program_with_excel.py
I use this command to compile everything into a single.exe file, so that I can use it on another pc.
Once this is done, I open my executable located in the 'dist' folder and when doing so I have detected several problems:
My executable file 'program_with_excel.exe' is too heavy for what I am trying to do, a few simple calculations. (317,948 KB)
When I open it, the following error appears and then my application closes:
I suspect it is because to run my program I use an excel sheet using 'pandas' where I place data and they are calculated with my program. How could this be resolved?
What would be the solution for this problem and be able to work with my executable?
I also attach a rar with my program and my excel sheet: RAR_EXAMPLE
Best regards.
The exe needs to have access to all its dependencies, just like the python script. If you moved it then it may not have that access. It appears from the error that this is the problem. A common way these exe files are transported is by putting it and each dependency in a zipped folder and using NSIS.
I'm unfamiliar with the terminology used for linking files into executables as they are compiled.
I want to write a Python script that extracts .icos from Windows executables that are viewable when you make file associations inside Folder Options. These are simply linked into the executable file upon compilation.
Then the script would sort the .ico files into individual folders based on their origin (it's supposed to extract all from subfolders/recursively) and even tell the difference between recently installed files and files that were left there previously.
Is there a library available that does such? Would I have to use a Python "Windows unlinker" or could I have it scan through RC resources too? Would there at least be a .DLL I can access with Python that does so?
I am looking to take a .exe file I've built using cx_Freeze, move it to my desktop, and have the ability to execute it while allowing it to reference the necessary directory. When I copy and paste the application, it tries to find its necessary files on the desktop rather than in the original directory.
Currently, all my files (including the .exe file) for this program are in the directory C:\Users\my_name\PycharmProjects\PROGRAM_DIRECTORY\build\exe.win32-3.4. I would like to take the file PROGRAM.exe, move it to my desktop (for more accessible execution) while still permitting it to reference all of the necessary files in the C:\...\exe.win32-3.4 directory. Is this possible?
Copying the .exe file from the directory and pasting it to the desktop will create a shortcut that has a default reference directory of its new location (the desktop), and this cannot be changed. A way around this is:
-Right click on the desktop
-Select "New > Shortcut"
-Browse for the .exe file or copy the directory into the field and add \PROGRAM.exe after it
-Name the shortcut
This shortcut will direct the execution to the parent file which remains in its necessary directory (C:\...\exe.win32-3.4) rather than trying to reference the desktop as the directory.