Read Python Logging Log File in Ubuntu - python-3.x

Environment
I am running code I found online and it uses the logging library to create logs. I am using python3.6.9 on Ubuntu 18.04. The code is a neural network Tensorflow code, in case that is somehow relevant.
The Problem + More Info
When I use vim to open the log files produced it looks like they are in binary.
Using the file command in Ubuntu I see that the type of the file is "data".
In the code the logger is initiated using logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
the file is being saved as a .0 and .1 files, i.e events.out.tfevents.1600700600.mycomputername.21941.1.
Please let me know any other information you need me to provide.
Thank you in advance for any help available.

Most probably the file you open is not one generated by the python logging module because the configuration shown: logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) is just logging stuff to stdout not to a file

Related

How to package/freeze a python code for unix?

I have a simple python program which will do process an xls file and append it. The problem here is i cannot install packages eg. XLWINGS on prod server (due to compliance issues). However I can install this package (XLWINGS) on my local system. I am thinking of writing a python program locally and create an UNIX executable file of it. My intention is that i will take this executable file/package to the UNIX server and run it without having to install the XLWINGS. Is this possible? If yes could you please help me with an example, I am new to Python. Thanks in advance.

I got a problem when I input any node cmd,

I got a problem when I input any npm cmd, it says
internal/modules/cjs/loader.js:584
Operating System: Windows 8 pro 64bit
What shall I do to solve this issue?
Your error message of:
Error: Cannot find module 'C:\Users\NUMAN ALI\myfirst.js'
indicates that Node can't find your myfirst.js file to run within your current directory of: C:\Users\NUMAN ALI. Your myfirst.js file isn't located within this directory so you need to move into the correct directory containing this file, or alternatively create this file in the current directory. Then you need to add your desired JavaScript within this file to run it.
With your comment of: "The file you have just created must be initiated by Node.js before any action can take place" I am going to assume you don't have this file in your current directory. Maybe you could try creating the file in a text editor, such as notepad at the very least on a Windows machine, and adding the JavaScript contents into this file. Then try re-running the file with a node myfirst.js. Check out this accepted answer here as I think this will help you out a lot. Also, for command line help for creating files, check out this link.
Hopefully that helps!

How to run Flask CLI from within PyCharm under Windows

I've been trying to get the Flask CLI to debug from within PyCharm with no success. I've tried the recommended procedures listed here. However, this doesn't work under Windows since flask.exe is an executable and not a script. Renaming flask.exe to flask does not work either. This causes the following exception:
Jetbrains has an active incident report in YouTrack for this, but there's been no activity done on it yet, with the Kanban State set to "Not On Board", so it looks like it's going to be sometime before the issue is addressed.
Any help would be greatly appreciated.
EDIT: Using Pycharm run works properly. Trying to run using the Pycharm debugger causes the exception
EDIT 2: Results after creating flask_debug.py file as recommended:
Firstly, rename flask.py back to flask.exe.
In PyCharm's Run Configuration dialog manually enter the full path to the Flask executable in the Script: text box. Don't use the browse button as it filters on Python scripts (.py files).
See screenshot. In this instance there is a virtual environment called "href" and the flask executable is in the Scripts sub-directory.
To use PyCharms's debugger create a file in the root say flask_debug.py:
from flask.cli import main
if __name__ == '__main__':
main(as_module=False)
Then setup PyCharm to run this script passing any Flask CLI parameters as required. See screenshot below showing Run/Debug configuration and the debugger stopped at a breakpoint.
Below shows Flask 0.12.2 quickstart app running under the PyCharm debugger and showing the defined environmental variable FLASK_APP.
In the latest version of PyCharm, there's an option to run by Module name instead of by file. Using "flask" as the module name works as well and doesn't require you to create a flask_debug.py file.
I'm attaching the screenshot of the working fileset and the Run/Debug Configuration for reference. This answer is thanks to the support provided by pjcunningham.

Cannot Find the Correct Working Directory in Python Spyder

I'm having trouble with the working directory in Spyder console. I'm trying to convert an xlsx file into a pandas array, but I keep getting the same error. I've changed the Run Directory in preferences and it should be the correct one.
screenshot of Spyder console
Sorry if this is a really newbie question I just really dont know where to go from here.
The path at the top right of the screen in Spyder will change the working directory of the IPython console. Set it to the desired working directory. Hit Ctrl+F6 to check the run configuration of your script and make sure it is set to run at the current work directory. See if that fixes the problem.
As others have mentioned, the os module provides a way of getting and changing the working directory directly through python, rather than changing the working directory settings in Spyder. Your second option is to do the following before importing the .xlsx file:
import os
os.chdir('C:/Users/mypath') # Change your working directory to your .xlsx file location
The other useful os function to check what your current directory is:
os.getcwd()
As for your current case, there isn't any issue. The runfile('', wdir='') text is simply letting you know which .py script you are running and for what working directory. There isn't any other output, because you haven't set anything to happen after you read the excel file to xls_file. Try adding a print(xls_file) statement to the end of your script and it should print the pandas DataFrame to the console.
(Spyder maintainer here) There's no error after you change your directory in the Run menu. runfile is the function used by Spyder to run a file in the IPython console. You are simply not getting any output after runfile because you're not printing anything. If you add the command print(xls_file) at the last line of your file, then you'll see the output.
You can always read a file giving the full path. From read_excel doc.
excelSheet = pd.read_excel(io="C://..//myfile.csv")

Using wingIDE with a new module (not recognized)

Using my terminal, the code "from PIL import Image" works perfectly and is recognized by my computer. This allows me to get images using the path address.
Here is my issue, when I open wingIDE and try the same code...this module isn't recognized.
Is anyone familiar with wingIDE that can help me?
I would assume PyCharm people might have the same issue with possibly a similar fix, any advice??
Thanks,
Adam
Most likely Wing is using a different Python than the one you installed Pillow into. Try this on the command line:
import sys; sys.executable
Then set the Python Executable in Wing's Project Properties to the full path of that executable (or in Wing 101 this is set in the Configure Python dialog from the Edit menu). You'll need to restart any debug process and/or the Python Shell from its Options menus.

Resources