Any possible way to change a .py but still run it? - python

I'm extremely new to coding and have almost no idea what I'm doing. I am trying to send a (.py) to someone but they do not have any version of python downloaded. I am wondering if there is any way to send it as a different file but still have them run it as they click on it? Would really appreciate some feedback.

As you mention, if there is no python interpreter installed, you cannot run the .py file directly.
You can convert your .py to binary executable so it can be executed directly. You can use PyInstaller for this.

Related

How to change default program/ file associations to open files using python script?

I need to make a way to install my code, and set default programs depending on file type.
I've been trying to make my python program easy for people who know nothing about python or programming to use.
As an alternative to an exe I want to make a script to do everything, including putting a shortcut to the python code on the desktop and a start menu folder.
The thing is I need to make sure that .py files automatically hey opened by python, and not the software, psychopy, which the user will install.
Is there a way to use python to change the default program for a given file type?
I've already tried:
Py2exe: I get errors (see post history)
Pyinstaller: I get different errors.
The errors with py2exe seem almost irresolvable.
I've used pyinstaller before and it worked. It won't easily work with this code because it doesn't work with an updated library/package I need. I have library b which depends on library a being up to date. So I can't revert back to a setup that I know how to make work.

Any other way to turn a tkinter python program file into a EXE file

I've tried using pyinstaller and the issue I'm finding with it is that when I compile my program from a .py file to a .exe some weird bugs show up and the program crashes (I have added threading). I also used py2exe but something keeps throwing an error with that too. If someone has a different way that works please let me know. Thanks!

What happens when you turn a python file into an executable?

What happens when you turn a python file into an executable? Does it get encrypted? What happens to the imported files? Can you revert it back into a normal .py file?
So I have this python file, let's call this main.py. I also have another file, let's call it scrambler.py. The scrambler.py is an encryptor/decryptor file. So, I imported it to main.py. Then I will turn it into an executable file. Now, we don't want people to see the enryptor/decryptor file. So, can people who doesn't have the source code get the source code of the imported file? Because, from searching, I saw that some people can get the source code of the main code using pyinstxtractor.py. I haven't tried it yet, but can you also get the source code of the imported file? (also do comments get included? I mean they are useless to the program). So that's why, the ultimate question: What happens when you turn a python file into an executable?
The file that I use to turn a python file into an .exe is Pyinstaller and is it different for every converter?
I hope this is a valid question. Thanks in advance.
Pyinstaller essentially bundles a python interpreter along with your python code in a folder. This folder can be put into an installer (using something like inno setup) to be distributed so end users can use it like a normal exe program. It doesn't compile to another language or anything. So no, your code is not private and while you can make it difficult to find certain bits, it is not impossible.
As described here, it is possible to convert to C and to machine code, but pyinstaller won't do that by default for you. Also note that the python bytecode files, while not legible, are not completely uncrackable.
See: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html
See here for more about the encryption option: PyInstaller Encryption --key

What should I put in the folder of my program if I want to embed Python to a C++ program?

I wrote a program with Qt and I embedded a .py file in it to do some work.
On my computer which has the Python interpreter installed, the program can run correctly, but when I run it on my roommate's PC, which has NO Python interpreter installed, the program crashed.
The part which is written with Qt runs well but when I push a button to call .py to do some work, the program crashes.
I think the problem is that I haven't put the std library and some other key files of Python into the folder of my program, but I have no idea what files should I pack into it.
So if the problem is really what I thought, what should I do to solve it?
Namely, which files of Python should be packaged into a program to run on the PC with no Python interpreter ?
Thanks in advance.
------------update------------------
As for the code of Python, it's just a hello-world for test and learning. I copy the whole Python34 folder into the program and the question has been solved:). Though it may not be a right way, it works.
Python's documentation has a reference manual for the C/C++ API.
The file I believe you're referring to is Python.h, though I'm no expert on this. It's considerably easier to embed C than C++, and this gives some of the more simple examples. As far as I know, you shouldn't need to worry about the interpreter for compiling to an executable.

Create a desktop icon for a Tkinter script

I have written a python script with a Tkinter GUI. I would like to create a desktop icon that will execute this script so that the end-user (not myself) will be able to double-click the icon and have the GUI load, rather than 'run' the script from the terminal or python shell and then have to F5 from there.
Is there a way to do this? I have googled many arrangements of my question but most answers seem to be normal python scripts, not ones which are Tkinter based.
I am using a Raspberry Pi with Wheezy and Python 2.7
Thanks in advance.
I create executables(icons that I click to start the programs I write) using 'py2exe'. I use windows 7 and I am not sure if it would work for you with Raspberry Pi, but a google search may clear that up for you. I will provide the link below. Basically you end up with a folder with the executable(icon) and also some files, without which the executable won't work. It's unfortunate that you get this extra 'baggage', but it's still handy and the best solution I have come across. I don't think there is a much better way, but I am not 100% on that. Interestingly, I found that you could delete most of these baggage files and the executable would still work, it was trial and error, but it didn't take long. If I want to send the folder to someone, I zip it first.
py2exe is here
If you need a 64 bit binary you can get it here, along with, actually, pretty much every other version. get py2exe here also
Besides creating executable file other option is create simple .bat file:
Open notepad
Enter "C:\ProgramData\Anaconda3\python.exe" "C:\Users\Your ID\script.py"
First part is path to python.exe, second to your python script
save file as .bat file, ex. "open_program.bat"
Now simply double click on saved .bat file icon should open your script.
I like using cx-freeze to convert python scripts to exe.
There is very easy to follow documentation to do this. In short, you create a setup.py script that specifies what libraries and packages you want to include or exclude in your application.
You can then run the build in the console and it will create a build folder, in which will be an Application File. You can create a Desktop short cut using send to and selecting desktop.
Documentation link
You can save the script as a .pyw file so the user can click on the file and the GUi would open

Categories