This question already has answers here:
Python Code Obfuscation [closed]
(7 answers)
How to obfuscate Python code effectively? [duplicate]
(22 answers)
Closed 2 years ago.
I have written python code and saved as program.py file.Now When i open "program.py" file it should be unreadable format.
Can anyone suggest me how to fix this issue.
You can creat pyc file with compileall:
Put your python files in a folder and run the command in this folder:(Source)
python -m compileall .
This command will produce a pyc file in __pycache__ folder. You can use this file like other python files:(Source)
python myfile.pyc
One way to do that is by compiling the source code using the py_compile module:
python -m py_compile my-py-source.py
The compiled source code will be in _pycache/my-py-source.pyc (relative to your current directory). And the code will still run normally when you run python my-py-source.pyc.
Related
This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 1 year ago.
I want to execute three python script that I have developed. I found one doubt, how could I do it using a python script?
I want to convert it into a .exe, because our solution is thought to be executed in machines without python installed so having an unique script would be helpful.
Edit: I don't know the cause of the closure, I know how to use pyinstaller, my question was how can I execute 3 python using a python script or if it is possible.
Any suggestion? Thanks!
To package script and all dependencies you can use Pyinstaller, see here.
To execute multiple script (or exe) you can write a bat file that start the 3 exe or use them as services, based on your needs.
Use pyinstaller it can convert python to executables. You can get it up and running simply by doing
pip install pyinstaller
pyinstaller myfile.py
This question already has answers here:
How can I convert a .py to .exe for Python?
(8 answers)
Closed 5 years ago.
I would like to convert a .py file to an .exe. I am using Python 3.6. I already tried py2exe and PyInstaller but they don't seem to work properly with Python 3.6.
Here is the traceback from PyInstaller.
So, let's try Pyinstaller first.
$ pyinstaller script.py --onefile
This will generate a script.spec file
in the spec file you can remove the console, debug mode etc
$ pyinstaller script.py
EDIT: Py3.6 isn't supported
If this doesn't work then we can try cx_freeze,
This question already has answers here:
Making a Python script executable by double-clicking
(3 answers)
Closed 5 years ago.
I have a command line app that I want to deploy. The only problem is that to run it you have to run the python file like this: `
$python application.py <arguement>
`. I have seen other applications made in python that can run like this but would require this input
$application<arguement>
How can I make this possible?
Thanks in advance
Assuming you are doing it in bash (Linux) or similar, then have the first line of your source (.py) file as
#!/usr/bin/python
(depending on the location of your Python interpreter) or possibly
#!/usr/bin/env python
Then make the script executable
$ chmod +x foo
and make sure the directory is in your $PATH or explicitly specify the directory in your command e.g.
./foo
This question already has answers here:
What do I use on linux to make a python program executable
(8 answers)
Closed 6 years ago.
Suppose I have a hellp.py python file. I found that I only can type command: python hello.py to run my command line, but how can I just type ./hello so that my system can run my hellp.py file?
If you want to run your Python script as an executable, put the right shebang at the top of your .py file. For example, hello.py might be defined as:
#!/usr/bin/env python
print('hello, world!')
Then you'll need to ensure the execute permission is set on the file:
$ chmod u+x hello.py
When you run ./hello.py, the interpreter currently on PATH (including one in a virtualenv if one is activated) will run the Python script.
There are other ways to do this as well with tools like PyInstaller, Py2App, Py2Exe, but I think this is what you're looking for.
EDIT: I noticed that the question specified wanting to just type ./hello at the command line. There are a couple of ways to tackle this. The first would be to simply knock off the file extension and have the Python file simply named hello. The second (and the way I'd recommend) would be to create a link to the file. I'd recommend creating a symlink:
$ ln -s hello.py hello
This way, the code is still obviously a Python file, but you can access it conveniently.
This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 9 years ago.
Is there any way or tool to automatically change python output script format (.py) to exe ? I want to run my app on every Windows computers including that haven't got installed python.
I had to do this a while ago and I had the most success with py2exe: http://www.py2exe.org/
You create a setup.py file which gives a list of what Python code you want to include in your executable, and it packages that up along with a subset of the Python interpreter into a single exe. Works specifically on Windows. (Linux and Mac generally already have Python installed so it's much less of an issue there.)