I have a python script I need to be able to run on a computer not having Python installed on it.
I do have found a compile.py example on this link: Can I somehow "compile" a python script to work on PC without Python installed?
When running it as "python compile.py python_script.py" in command prompt, it seems to work, but py2exe seems to compile everything in Python; language-packages etc. This in turn makes the output directories very, very large, when all I really want is an .exe-file. It also takes a very long time to compile.
The script I am using just imports pandas, datetime and a few other packages.
Is the compiler supposed to take that much time and space? Is there another, easier way than explained in the link above?
Thanks
I would recommend using pyinstaller. There's an option for an .exe only. In terms of size, it'll be just as large, but will only be the single exe.
Related
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.
Im working in a simple idle game in python and its interface is made trought PySimplegui, then it came to me two questions:
How do i transform my python code into an executable file?
There is any way to make my code become an Android application? if yes, how?
There are many solutions available. You might want to look at py2exe.
I'm not sure if you can turn a python program into an android program. PySimpleGUI doesn't work with android.
There's a very simple solution to this. Use the PyInstaller module to convert your python script to an executable file. The best thing about PyInstaller is that it will fetch all your dependencies and stack all these to an executable file. You can follow this simple line of code from your script directory in your command prompt
pyinstaller --onefile -w [your_script_name.py]
You can also watch this video, this guy explains it pretty well : https://youtu.be/UZX5kH72Yx4
Also here's the PyInstaller manual: https://pyinstaller.readthedocs.io/en/stable/index.html
Now to convert into .apk file, to the best of my knowledge I don't think you can directly convert your python script to .apk. I would recommend using KIVY to build an android app by python.
I am sharing a tutorial here though I don't know how good this is, you can check for yourself: https://youtu.be/mUdnjNGePZw
I have 7 scripts that all call eachother at some point, so I want to compile them all and have it as a single .exe that I can run anywhere. Pyinstaller isn't working for me, it keeps coming up with errors such as WARNING: lib not found: api-ms-won-crt-time-l1-1-0.dll dependency of c:\python35\DLLs\_ssl.pyd
Another way to compile your scripts to an .exe is cx_freeze. Or like creyD said Pyinstaller.
Have you tried to use another program (like py2exe or similar)? If this doesn´t help and you can´t merge them into one larger script (what would be my prefered way) maybe you could should check on the dll Pyinstaller can´t find, cause it seems like one of your scripts would need it.
If you need to include the dll file into your exe maybe this Post will help you...
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.
Here is the problem I am trying to solve. I don't have a specific question in the title because I don't even know what I need.
We have an ancient Hadoop computing cluster with a very old version of Python installed. What we have done is installed a new version (2.7.9) to a local directory (that we have perms on) visible to the entire cluster, and have a virtualenv with the packages we need. Let's call this path /n/2.7.9/venv/
We are using Hadoopy to distribute Python jobs on the cluster. Hadoopy distributes the python code (the mappers and reducers) to the cluster, which are assumed to be executable and come with a shebang, but it doesn't do anything like activate a virtualenv.
If I hardcode the shebang in the .py files to /n/2.7.9/venv/, everything works. But I want to put the .py files in a library; these files should have some generic shebang like #!/usr/bin/env python. But I tried this and it does not work, because at runtime the virtualenv is not "activated" by the script and therefore it bombs with import errors.
So if anyone has any ideas on how to solve this problem I would be grateful. Essentially I want #!/usr/bin/env python to resolve to /n/2.7.9/venv/ without /n/2.7.9/venv/ being active, or some other solution where I cannot hardcode the shebang.
Currently I am solving this problem by having a run function in the library, and putting a wrapper around this function in the main code (that calls the library) with the hardcoded shebang in it. This is less offensive because the hardcoded shebang makes sense in the main code, but it is still messy because I have to have an executable wrapper file around every function I want to run from the library.
I would change the environment variable PYTHONPATH and also the environment variable PATH. Point PYTHONPATH to your virtual environment and PATH to the directory that contains your new python executable, and make sure the path to your python executable comes first.
I accepted John Schmitt's answer because it led me to the solution. However, I am posting what I actually did, because it might be useful for other Hadoopy users.
What I actually did was :
args['cmdenvs'] = ['export VIRTUAL_ENV=/n/2.7.9/ourvenv','export PYTHONPATH=/n/2.7.9/ourvenv', 'export PATH=/n/2.7.9/ourvenv/bin:$PATH']
and passed args into Hadoopy's launch function. In the executable .py files, I put the generic #!/usr/bin/env python shebang.