Having Problems running Python on old CE device - python

I have a Python interpreter that runs on a CE device and is a C application. Currently the device comes configure with a root '\' folder and a '\Application' folder. If I install and run python on the '\' drive everything is fine, but if I try to put it on the '\Application' drive it will not run.
In digging further, the problem is with the CreateFileW call. When trying to access '\PythonLib' I get a normal error code of 80 saying the file exists, when I try to access '\Application\PythonLib' I get an error code of 5, or Access is Denied.
Has anyone had any experience with this? Any C++ app we develop in Visual Studio 2008 and run on the device has no problem accessing '\Application', but anything we try with Python can not seem to resolve that path.

I found that the problem was the attributes on the CreateFile calls. For some reason on our device the '\' directory needs different attributes then the '\Application\' folder. mainly I needed to add the FILE_FLAG_BACKUP_SEMANTICS bit to the FlagAndAttributes field.

Related

Is there a way to run python script in a Core-Network emulator?

I am using Core-Network Emulator (just like packet tracer) in an Ubuntu system to connect a network of systems. I intend running some python scripts on any of the systems but I can't access the text file (.py file) on the local ubuntu machine from the emulator. I tried running the script directly inside the command prompt of the systems on the emulator yet I kept having this error No module named scapy.all. Again, I tried using os.sys.path.append('....'), but it's still showing error too. Can anyone help please?
try using the full path name (e.g., python3 /user/john/test/script.py) - assuming appropriate permissions and python modules are in place.

Using VSCode Python extension with Jupyter and RemoteFS?

I use the RemoteFS extension in VSCode to connect to my remote SSH server. When I open a .py file on the remote server in VSCode, and then add #%% comment to the .py file, I don't get the option to run a Jupyter cell like I would locally.
Has anybody gotten VSCode's Python extension working with it's built-in Jupyter support and the RemoteFS extension?
We had an overly restrictive file check for when we allowed our "Run Cell" commands to show up and it was limiting it to local files only. I've fixed that issue in the following PR here:
https://github.com/Microsoft/vscode-python/pull/4191
I verified that I was seeing the cell commands using Remote FS after that. Sadly this just missed the cutoff for our recent January release, so it won't show up in the extension until later in February. If you want to check out the fix you can access our daily development build here:
https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#development-build
That build has the fix already, but it's not the full public release.

What should a .py file be opened with? [duplicate]

I installed python 2.7.13 and the google original App Engine SDK for PHP. I created my first project on google console and When I am trying to deploy the project file from cmd using
appcfg.py -A *project-id* update *project-folder*
Instead of running, its just being edited in chrome. Please refer attached picture chrome editing appcfg.py
you are probably running Windows and have probably wrongly associated your .py files with Google Chrome (like it is associated to .html files)
Chrome acts as a text viewer in that case.
Either reinstall python (to fix associations, that would be the best thing to do, python has a "repair" option when running the installation, no need to uninstall/reinstall) or remove your user registry key:
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
which must contain something wrong like:
#="\"C:\\Programs\\chrome.exe\" \"%1\"
and let system file associations take over.
or as a final workaround, if you cannot, just use python prefix to force python execution instead of relying on file associations:
python appcfg.py -A *project-id* update *project-folder*
(python must be in the path, and appcfg.py must be in the current directory or in PYTHONPATH)
note that the shebang #!/usr/bin/python doesn't help here (on Linux it would have helped)
Another way to repair associations manually is given in another answer of mine

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.

Packaged Python program for Mac will not run when downloaded

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.

Categories