Compiling Python File for Distribution - python

I have a really simple Python script. It’s written in a single file however I did have to install two things using pip. I’ve created this on Mac and I need to somehow compile it into a runnable application on windows. I’ve spent hours trying to use pyinstaller to make it into an exe file but I don’t think the dependencies are included in that ... I’ve also tried creating a virtual environment using venv but that doesn’t work either. I first tried using pyinstaller on Mac which was really easy but didn’t run at all when transferred it to windows. I then have been trying to do it on windows but it’s just very difficult and it’s just one error after another. I finally managed to build the app on windows using pyinstaller but it said “failed to execute script ...”
So does anyone know any simple way to make it into a runnable application? Doesn’t have to be an exe.
Thanks in advance.

Have you tried using py2app. To install it, type: pip install py2app.
Check out This link for more information.

Related

in python is there a way to show CLI app to someone who doesn’t have python installed

well I made something and want to show it to some of my friends but since they are not into coding they don’t have python installed in their computers is it necessary to download it?
Create your program into an executable so it eliminates the Python installation dependency.
Ref - https://datatofish.com/executable-pyinstaller/

How do I make my Python Script into an Executable .dmg file for Mac?

Right now, I have a python script that when run, opens up a python window using a package "kivy", while processing data using many other packages. Is there a way for me to combine all of these into a .dmg file that when run, installs all the necessary packages and launches the python application as a .app file?
Know there's a lot of factors and this is really specific, but any help would be appreciated :D
You can use py2app to do this.
My recommendation would be to use py2app - https://py2app.readthedocs.io/en/latest/
Here's some installation instructions.
And here's a small tutorial because why reinvent the wheel - they explain it well, it's a really simple process.

Modules Not Found - I cannot externally run a .py file developed using PyCharm

I am using PyCharm to develop a python project, which uses an external library called win10toast. I have installed win10toast using PyCharm. However, when I tried to run the .py file using cmd (i.e Externally running the python file), an error shows up:
ModuleNotFoundError: No module named 'win10toast'.
I have python 3.6.4. I installed win10toast using PyCharm.
from win10toast import ToastNotifier
I expect the program to run without any error, but currently I am getting the ModuleNotFound error.
Python can be tricky to run properly because it is sensitive to where you installed your dependencies (such as external libraries and packages). If you installed Python to one directory, but accidentally installed the external library to another directory, when you run your .py program, it will be unable to call from the external library because it doesn't exist in the same library that Python is running from.
Lookup where you installed Python on your computer and then find where you installed the external library. Once your find where you installed the external library, move its entire package content to the same directory where Python is installed. Or better yet, reinstall the external library with pip into the same directory as Python.
If you're on Mac, Python and its related dependencies are usually stored somewhere in /User/bin. If you're on Windows, it will be stored somewhere in your C:// directory (possibly somewhere in C:\Users\username\Local\AppData). If you're on Linux, it will be stored somewhere in /usr/bin. Whatever you do, don't move Python from wherever it is because sometimes that can mess up your system for certain operating systems like Mac, which comes with its own version of Python (Python 2.7 I believe, which is outdated anyway).
Lastly, you may have two different versions of Python on your computer, which is common; Python 2.7 and Python 3+. If you wrote your program in one version, but ran it from the other, the external library can only be called from whichever Python version you installed it to. Try running your .py program with python3 instead of python (or vice versa) and see what happens. If it works with one python version over the other, that tells you that the external library is installed in the other version's directory.
That should solve your issue.
I would suggest that you not use PyCharm to install packages, at least not
if the result deviates in the slightest from doing a "pip install" at the command line. I see no reason to involve PyCharm in configuring Python installations. It's just asking for trouble.
I admit that I'm not familiar with the practice I'm suggesting you avoid. I've been using PyCharm since pretty much the week it came out (was an avid user of the IntelliJ Python plugin before that), and have never once considered doing anything but installing Python modules at the command line. That way, I'm sure right where those modules are going (into which base Python install or venv). Also, I know I'm doing all that I can to minimize the differences that I might see between running code in PyCharm and running it at the command line. I'm making my suggestion based solely on this practice having never gone wrong for me.
I have multiple base Python versions installed, and dozens of venvs defined on top of those. PyCharm is great at allowing me to indicate which of these I want to apply to any project or Run/Debug configuration, and utilizing them seamlessly. But agin, I administer these environments at the command line exclusively.
I still experience issues in switching between the command line and PyCharm in terms of one module referencing others in a single source tree. My company has come up with a simple solution to this that insures that all of our Python scripts still run when moving away from PyCharm and its logic for maintaining the Python Path within a project. I've explained the mechanism before on S.O. I'd be happy to find that if anyone is interested.
The library win10toast installed in the directory: YOUR_PYCHARM_WORKSPACE\PycharmProjects\YOUR_PROJECT_NAME\venv\Lib\site-packages
but when you are running your program using cmd, pycharm interpreter uses site-packages directory that you installed python at there. for Ex: C:\Python27\Lib\site-packages
So, you can install the win10toast library to this windows directory using pip.

How can I run my python scripts on a windows machine without installing extra libraries?

I'm working on a python script but it uses a library called Selenium to perform most of its tasks. This script needs to be able to run in a windows environment and I can't go through the trouble of installing Selenium on every machine that I decide to run this script on. I've heard of py2exe but haven't tried it out and am not sure if it will help here. Will I be able to run my script without having to install selenium when using py2exe? It doesn't seem like it would work since selenium isn't built into python.
I'd like to be able to run this script on Windows without having to install python but I'll be satisfied if I can get it to work without having to install selenium. I'm not sure how possible this is and I'm actually fairly new to developing in python so I don't know if this idea will work out.
Actually, other people will be using this script and it would be best if they don't have to go through the trouble of installing python and the selenium library just to use the script. They aren't exactly familiar with python or programming in general, so installing selenium could be a problem for them. I'd like to make the use of my script as user friendly as possible.
The script mainly deals with automating a website. I understand that this can be done in vbs and it would be better in vbs for windows but I've already made it in python and don't want to go through the trouble of re-writing it in vbs, since I've already spent a lot of time on this already.
I've tried many Google searches and can't find much about this topic which leads me to believe it's not possible. The closest solution I've found is py2exe but will it still work if my script uses a library not built into python?(selenium)
I'm sorry if this question was kind of nooby, I'm just trying to learn. I appreciate any help! :)
Yes, py2exe will build an executable that includes python so that python will not need to be installed on any extra computers. When you build the executable with py2exe you can include or exclude modules in your build.
PyInstaller is another good module for building executables, it will automatically bundle any includes. Like py2exe you can bundle everything into one executable, include extra data files, hide console windows and more.
You can include external libraries in py2exe
From the py2exe FAQ,
How does py2exe decide which modules you need?
To determine which modules should go in the final .exe file, py2exe does a recursive search of the script that you are packaging to find its dependencies and, in turn, all of their dependencies. This process is written so that it can output extensive debugging information, showing you which modules convinced py2exe to include which other modules. To display this debugging trace, run the py2exe "module finder" code standalone with at least one -d option to turn on "debugging":

Python installing PyQt4 module to custom software

This is something I've been researching for past few hours but so far nothing come out of it.
Basically I have software that use Python 2.5.5. It does not have QT module in it.
So in my attempt to install it I did this.
Downloaded executable QT PyQt4-4.10.2-gpl-Py2.7-Qt4.8.4-x64. Run Exe. It installed in python 2.7 site-packages.
Then I moved that folder to my software Python 2.5.5. Now there was no site-packages folder so I created it.
Next step was to go over this instruction http://docs.python.org/2/install/ and use Alternate installation: Windows (the prefix scheme) with my file location from inside program. But I cant run python setup.py install --prefix="\Temp\Python" (with my location of python) because python is not defined and so on. I'm pretty sure thats the wrong way to do it. So how or where do I look for information as to how to do it? The software itself dont have any documentation.
Thanks, bye.
That binary version of PyQt4 only supports python2.7, so no matter what you do, you won't get it to run with python2.5.
The last PyQt4 version with a binary for python2.5 is PyQt4.9.4, so if you want to have any chance of making this work you should try with this version.
Note however that the software you distribute like this will also only run on python2.5.

Categories