Packaged Python program for Mac will not run when downloaded - python

I have Python program that I packaged with py2app so that the program query_agent.py became query_agent.app. I have a Java program that launches query_agent.app with the following command:
open ./query_agent.app --args abs_path1 abs_path2
, where abs_path1 and abs_path2 are string arguments.
I put everything in a folder and when I launch the JAR that eventually launches query_agent.app, everything runs perfectly as expected.
So I zip this folder so I can distribute it to others. Before sending, I put the zip on a flash drive and unzip it on another Mac computer to test it. Again, the program works as expected even when unzipped.
However, when I send the zip as a message attachment in an email, or upload the zip to a file hosting site like MediaFire, the program no longer works when unzipped. When I unzip the downloaded zip file on any Mac computer, right-click and open, I get the message:
query_agent Error
When I open the console, it shows the cause of the error:
The STATS_FILE_LOCATION points to a file that I am trying to write to. This file is located at query_agent.app/Contents/Resources/resources. As a reminder, this works fine if I use the version of the zip before it was uploaded.
It appears that the main error is shown in the last line as
OSError: [Errno 30] Read-only file system: 'resources/status.txt'
The first thing I notice is that it is finding my source files in the /private/var/folder/... location. I believe this a temp location, which may be why I am getting the "read-only file system" error. I never intended for anything to be read from or written to any location outside of my main applications folder.
I also get the message:
Detected missing constraints for <private>. It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.
So my question is: Why doesn't my program work if I upload it, download it, unzip it, and then try to run it?
It works before the upload on any Mac computer I put it on, so the fact that it gets zipped is not the issue. I hope that these obscure error messages can provide some hints to why this is happening. Any help with solving this problem will be greatly appreciated.

Related

Python Script generates 500 Internal Server Error but code in different file works fine

I have a Python script with the following code:
#! /home/flohosting/PythonTest/PythonTest/bin/python
print()
print("hello world!")
I'm running Python 3.6 on a GoDaddy VPS. The Python 3.6 is a virtual environment. This script works just fine. The problem arises when in Virtual Studio Code I open a new document, copy the code above from the working .py script and then paste it into the new .py script, upload the script, CHMOD to 755, and try to execute. Then I get a 500 Internal Server Error. It makes no sense to me.
I've logged into my SSH with PuTTY and tried to CHMOD a+x file_name.py where "file_name" is the exact filename and it still doesn't work. I can't think of anything else to even check to see why the script works in a file that's been on the server for 2+ months and not in a new script I upload and CHMOD to 755. Thanks for any suggestions.
EDIT: the link to the script working is http://www.dockethound.com/bernard.py
The link to the non-working script is http://www.dockethound.com/hello.py
EDIT 2: I figured something out and it is working though I have no idea why.
When using CuteFTP 9, I upload on "AUTO". I decided to select ASCII and then try uploading again. When I uploaded I got an error that said "This appears to be a binary file you want to upload with ASCII. Are you sure?" So for some reason the file is being saved in a binary format or something that CuteFTP recognizes as a binary format and is uploading it in binary which causes Apache issues when trying to run it. BUT if it's uploaded in forced ASCII mode, the problems are solved.
Jarod
In my situation, using the Auto setting in CuteFTP 9 allowed CuteFTP to determine that the file types with .py were binary files so the files were transferred via binary and not ASCII. Forcing ASCII fixed the problem, then going into TOOLS->Global Options->ASCII types and adding PY to the list fixed the problem.

FileNotFoundError Python Script

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

How to Give Python Permission to Write Files

I'm learning Python and don't quite have the vocabulary to describe this. However, I can't seem to save files created in Python to my Window10 computer. I discovered this while seeking a help to try to get a file to save in Pandas. I then discovered the same problem when creating a db using SQLITE3 the script seemed to have fun but no database files appeared.
Does anyone know how to fix this? FYI I've got a dual boot Ubuntu machine, I can save files via Python in Ubuntu but really need it to work on my windows machine too.
I am running python via Jupyter Notebook.
I had to make a couple changes to the code snipped that you linked in order to get this to work.
A difference between windows and linux is the file path deliminator is a forward slash:
df.to_csv("tests/ysi_test_files/filehere.csv", index = False)
If you want a hard absolute path to a file, then do something like:
df.to_csv('C://Folder//myfilename.csv', index=False)
Again, if you copy the folder path from a windows folder you will get the backslashes instead of forward slashes. You will need to change those in your code to save the file:
C:\Users\myuser\Desktop\python\
to
C:/Users/myuser/Desktop/python/
If you are running the python script from command prompt then right click on it and run as administrator should solve the issue.

Python correctly finding and reading windows application event logs

so my ultimate goal is to use python to read a specific application's windows event log when triggered by a file update.
Here is my problem, python I believe does not have access to the event logs stored in C:\Windows\System32\winevt\Logs. Whenever I try to read the files I get the following error:
WindowsError: [Error 2] The system cannot find the file specified
I tried every form of escaping, string split/join and using quotes on the file path and I always get the same error. I even cheaply used the os.system('dir "C:\Windows\System32..."') command in the python command prompt to list directories higher in the path for the log to verify access and I receive similar errors up to the C:\Windows\System32 directory, that one will list just fine.
Example:
C:\Windows\System32\winevt\Logs - File not found
C:\Windows\System32\winevt - File not found
C:\Windows\System32 - Lists files
I know these directories exist. So from here I figured I could use a bash script to copy the event log into a temp folder for python to read. I wrote a real simple bash script containing:
xcopy /Y "C:\Windows\System32\winevt\Logs\XXXXXXX" c:\Temp
(XXXXXXX) being the name of the log I want to copy for the python script.
The bash script runs fine on its own but when called by my python script it fails, refuses to copy the file because it can't find it. I have even tried using py2exe to create an exe to then run in administrator mode. This failed too. With similar errors of the file not found. I'm not sure I understand the permissions python uses to call the script and why the bash script cannot copy the file even when it can do it in a normal command prompt.
Any suggestions or flaws you can point out in my logic would be great. I am very stuck.
You are using a 32bits python on a 64bit install of windows.
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64
You can use os.listdir("c:\windows\sysnative\winevt\logs") as a workaround to read from the real system32 dir from a 32bit python interpretter runing on a 64bit windows...
Sources:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
http://support.microsoft.com/kb/942589

python packaging problem

hi develop code in python to scan wifi and send to the server, its working fine when execute manually, but i packaged it via http://www.python-packager.com by uploading my .py file and they create package for me as deb file for linux, and i download it and install the package but nothing happen when i click the .exe or set it as startup application,
why this happen, nothing is printed in the terminal
in .py file i'm having print statement to check manually to list out the wifi scan value, data to post to the server, response from the server once send
how this can be solve
thanks
I'm the maintainer of the project, I thought I'd chime in and give my 2c.
I had a look at your program. With .deb's, it installs everything to /opt/application-name. So to debug-it, run it from the command line. eg. "/opt/Jemapoh_Wifi/Jemapoh_Wifi".
I just ran it myself and your programs gives the error "IOError: [Errno 2] No such file or directory: '/opt/Jemapoh_Wifi/config.txt'". So your program's looking for config.txt but you didn't upload it with the program. :-)
If you have any further problems, please email me or report a bug on Launchpad - http://launchpad.net/python-packager. There'll be a re-vamped version coming out soon, hopefully it'll make things easier to understand.
Hope that helps/makes sense.
Cheers,
Jackson
"How this can be solved?"
Use a standard packager. Read this: http://docs.python.org/distutils/introduction.html and this: http://pypi.python.org/pypi/pip and this: http://pypi.python.org/pypi/zc.buildout

Categories