Mac no longer recognizes .py files? - python

I usually code on Atom, and recently, my Mac has just started to stop recognizing .py files as python files. It always recognizes those files now as TextEdit files, so that I can't even run the file without copy pasting the code into another file that my computer recognizes as a python file to run the code. Thanks for any help in advance.

Related

Problem with correctly running .exe file from python file

I want to run .exe file from python file, but there is problem with reading from txt file.
Exe doesn't throw any errors, but it looks like it doesn't even open any .txt.
Additionally, .exe works well, when I enter the folder and run it manually.
How I run .exe in python:
subprocess.check_call(['D:\Projects\PythonProjects\PrivateGithub\MinMax\EXE\Run.exe'])
Should I do something 'special' to be able to read from files?
Try this code to run the exe:
import os
os.startfile('D:\Projects\PythonProjects\PrivateGithub\MinMax\EXE\Run.exe')

Sending Python .exe file to a machine without Python

I've created an executable file using cx_freeze that contains a simple Python script. The .exe file works on my PC (I have Python installed) but is it possible to send it to a colleague, for example, that doesn't have Python on their machine and will it work? The goal is to package useful Python programs and make them available for others to use even if they don't have Python.
I've played around with it a little bit and it doesn't seem to work on non-Python enabled machines. I've sent just the .exe file (didn't work), just the 'build' folder (in a zip file-didn't work) and I've even zipped the whole folder that contains the .py files and the build folder-that also didn't work. However, I thought this was the point of creating the .exe file? Any guidance would be appreciated.
Thanks

How to get a file from the files on my computer to JupyterLab?

I am very new to this and struggling with the basics. I have a csv file /home/emily/Downloads/Roger-Federer.csv The textbook says that I need to "extract the file and download it to my current directory" on JupyterLab (I am using Python). What does this mean? How do I do this? Thank you
Every running program, including JupyterLab, has a "working directory" which is where it thinks it is on your computer's file system. What exactly this directory is usually depends on how you launched it (e.g., when you run a program from terminal, its working directory is initially the folder your terminal was in when you ran the command, but it's possible for a program to change its own working directory later).
Your file path indicates you're on Linux, so I'd suggest opening a terminal in your JupyterLab and running pwd to have it print out its current directory. (You can also run !pwd in any open notebook if that's easier.) You should then copy your CSV file to that directory.
If you do that, then from your Python code, you can just open the file locally, like open('Roger-Federer.csv') or pandas.read_csv('Roger-Federer.csv'). You don't have to move the file to open it from Python, though, you can just give it the entire file path, like open('/home/emily/Downloads/Roger-Federer.csv'), and that'll work just fine too.

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

My exe doesn't execute after I decompiled and changed the code

I have an .exe file where file compiled by py2exe in my .exe folder I have some .dll files, one .exe file and library.zip file and inside this zip I have to many .pyccompiled files.
I have decompiled this files from library.zip using Easy Python Decompiler and that program created me new file where I can see and change my code.
I have opened this file where I needed and I changed my code using python editor and finaly I saved as new script code with the some name and extension .pyc
with purpose to replace first .pyc.
zip again library folder and I tried to run .exe prgram but after the changes the program doesn't execute.
What have I done wrong in my task? Do I need to re-compile again in some way?
pyc and py file are NOT the same. While they represent the same code, they are totally different :
the py file represents the code you are typing, can be interpreted by the python interpreter, is not native, and is portable
the pyc file is a compiled version of the py file, that is not portable, not intended to be modified by an human, but faster
You cannot swap them and expect it to work. You will need to compile it to pyc before. You will find more information here : How can I manually generate a .pyc file from a .py file

Categories