stack overflow has been a great source since I first started learning Python, so wanted to thank the community... anyways first time poster.
I'm new to python so excuse me as my terminology may be a bit off.
I have a script that uses pandas read excel. I give it a xlsx doc name and it finds the file in the same folder as the script.
I can run my script fine from my terminal.
Using pyinstaller, I can run the script fine from a windows pc as an exe.
When I try to run the pyinstaller's unix executable, on mac, the read excel function fails to find the doc and cwd function returns (user/myname), rather then using the same directory as the executable.
Am I doing something wrong here or should I be adding something to help the executable find the file? Any help would be greatly appreciated!
Script works fine if I move the file to my user/myname folder, but I would assume since the pandas function isn't given a specific directory to check, it should just be checking the folder I run the executable from?
Related
I have used several tools (pyinstaller, cx_Freeze, py2exe) to convert my .py file to .exe file. But with each one of these, the resultant .exe file closes as soon as it runs. Here is a screenshot of the exe file created form pyinstaller.
I have looked at several answers on SO and other platforms but haven't been able to find a solution. Any help would be greatly appreciated.
My apologies for not being able to type these traccebacks out here as I had to take a quick screenshot as the window closed in a second.
The .py file runs fine on its own; there's no issue with the code.
I had this problem about a year ago with pyinstaller and this 2 methods helped me:
Adding import pkg_resources.py2_warn to my script
Using --onedir instead of --onefile
You can also do it using cmd:
pip install pyinstaller
cd followed by the location where your Python script is stored
so an example is:
cd C:\Users\Ron\Desktop\MyPython
then:
pyinstaller --onefile pythonScriptName.py
instead of pythonscriptname.py, put in your python file name.
When you do this there should be a new file called dist in your directory. Wait for a few mins and there should be an .exe file in there.
Here's a temporay solution: I removed all imports related to the googleapiclient for google docs. The .py file gets compiled properly after that.
More Context: There seems to be some issue in this particular library library that causes issues. I have tested the given solutions, they don't seem to work for me. I'll update this answer if I find a "permanent" solution.
Stack Overflow has many questions about
How to give someone else a python script protecting the source code
How to compile python files
How to create packages and deploy the code
But I could not find the answer to my problem:
I want to give someone else my python script, without giving him the source code. My current attempt is compiling the file and giving away the .pyc file.
This is for sure not the best solution. Moreover, my code is made by different files. To offer a single executable pyc file, I put the code all together in a single file before compiling it: a true hell for a developer
How can I obtain my goal in a cleaner way?
Side-notes
I know .pyc files are not going to hide so much, but it is for sure better compared to giving .py files
Still, .pyc files can be incredibly problematic (as they can be system-dependant)
You can create a .exe file using pyinstaller.
pip install pyinstaller
then, open terminal in your source code directory and use the command:
pyinstaller --onefile source.py
If you have database connection with python file then it can be added using:
pyinstaller --onefile --add-data 'database.db:.' source.py
Here, :. shows database.db is a source data file and it will copy on the top level of your python application.
using "pyinstaller sroucecode.py --onefile" command will generate an executable file on Windows. This can be a way should it be desired to ship the functionality but hide the code.
There is tool, which might help you to achieve described outcome, but only if destination machine is able to run .exe files.
I need to make executable file on OSX/Mac. I have python3 script that uses excel file. Executable file also should be able to work just by double clicking the icon and also have python packages. I mainly work with Ubuntu18 but have access to Mac for few days.
What I've tried so far:
I've written a short bash script that activates python environment (with "source activate" command) and runs python script. Appified the script with this: https://gist.github.com/anmoljagetia/d37da67b9d408b35ac753ce51e420132
I know that terminal commands work but double-clicking the app in Mac does nothing.
With pyinstaller converted bash+python script to exe, then with wine tried converting that to executable program but that double-clicked program does nothing.
Tried py2app, but in the mac terminal it says "cannot execute binary file".
Does someone have any recommendations for my problem? As I've mentioned there are few main requirements:
works by double-clicking
works on mac
has all python packages
is able to read specific excel file (I will know the name of it, but just path may be confusing in some versions, because I would like to use relative path or something like [pwd]/file.xlsx)
Anyway, I'm having most problems with the first two points but don't want to forget the last two.
Thank You for help!
I'm trying to run a fairly simple Windows Python 3.7 script that uses Webbot. The script works beautifully from within Python's IDLE, so I know the code that I've written works and there's nothing wrong with it, but I want to run it as an .exe instead. However after packaging it with Pyinstaller (which normally works wonderfully), although the Pyinstaller process runs, the actual program produced won't run at all.
I had a look here but this didn't help much. If I compile using:
pyinstaller file.py
as suggested, when I run the resulting .exe, the program closes instantly, with no error message.
If I instead try:
pyinstaller --onefile file.py
or:
pyinstaller file.py -F
Then when I run the compiled .exe I get this message:
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\KimJiwoo\\Appdata\\Local\\Temp\\_MEI51362\\drivers\\chrome_windows.exe'
So I guess I need chrome_windows.exe?
I figured I could just give the program this file, but the _MEI folder is a temp directory that seems to be created each time. I've tried putting chrome_windows.exe in other places, like in System32 or the same directory where file.py or the created .exe is, the same error occurs.
So I guess I have to make this program see chrome_windows.exe somehow but I'm not sure how. I do already have
from webbot import Browser
in my script, but clearly I need something more than this. Not sure what.
Note that I'm not that fussed whether the Python program includes chrome_windows.exe within its own created .exe or not. I mean, that would be nice, but if it's simpler coding-wise to just shove chrome_windows.exe into a directory on the computer the program is running from, and have something in the program pointing to it there, then that would also be fine. I feel like the answer to this is probably simple so I'm after the most simple, elegant solution possible.
The path for the webdriver in the Webbot source seems to be driverpath = os.path.join(os.path.split(__file__)[0] , 'drivers{0}{1}'.format(os.path.sep , driverfilename)) (when you compile to exe, the files directory is in TEMP).
You can use the source to make your own class and change the directory path (github.com/nateshmbhat/webbot/blob/master/webbot/webbot.py).
I am trying to get an executable file from Python script (MAC OS). But the thing is I'm not in the simplest case : I have a main Python script calling a bash script, and the bash is calling other python files. Plus those scripts need data files (pickle and csv files). Furthermore, I don't know if it's important but my code is creating other datafiles for using them afterwhat.
Is it even possible to get an executable from that? I tried with py2app and pyInstaller:
With py2app I think I understood how to pass data files and python scripts to setup.py, but what about the bash? I pu it with the python scripts in the option "py_modules" or with the data files and it's never working
With pyInstaller I didn't even find how to pass several python scripts, I tried to import them in the main file but it didn't work.
So does someone have an idea?
Thanks a lot,
Marie