I'm trying to convert a fairly simple Python program to an executable and couldn't find what I was looking for, so I have a few questions (I'm running Python 3.6):
The methods of doing this that I have found so far are as follows
downloading an old version of Python and using pyinstaller/py2exe
setting up a virtual environment in Python 3.6 that will allow me to do 1.
downloading a Python to C++ converter and using that.
Here is what I've tried/what problems I've run into.
I installed pyinstaller before the required download before it (pypi-something) so it did not work. After downloading the prerequisite file, pyinstaller still does not recognize it.
If I'm setting up a virtualenv in Python 2.7, do I actually need to have Python 2.7 installed?
similarly, the only python to C++ converters I see work only up until Python 3.5 - do I need to download and use this version if attempting this?
Steps to convert .py to .exe in Python 3.6
Install Python 3.6.
Install cx_Freeze, (open your command prompt and type pip install cx_Freeze.
Install idna, (open your command prompt and type pip install idna.
Write a .py program named myfirstprog.py.
Create a new python file named setup.py on the current directory of your script.
In the setup.py file, copy the code below and save it.
With shift pressed right click on the same directory, so you are able to open a command prompt window.
In the prompt, type python setup.py build
If your script is error free, then there will be no problem on creating application.
Check the newly created folder build. It has another folder in it. Within that folder you can find your application. Run it. Make yourself happy.
See the original script in my blog.
setup.py:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("myfirstprog.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "<any name>",
options = options,
version = "<any number>",
description = '<any description>',
executables = executables
)
EDIT:
be sure that instead of myfirstprog.py you should put your .pyextension file name as created in step 4;
you should include each imported package in your .py into packages list (ex: packages = ["idna", "os","sys"])
any name, any number, any description in setup.py file should not remain the same, you should change it accordingly (ex:name = "<first_ever>", version = "0.11", description = '' )
the imported packages must be installed before you start step 8.
Python 3.6 is supported by PyInstaller.
Open a cmd window in your Python folder (open a command window and use cd or while holding shift, right click it on Windows Explorer and choose 'Open command window here'). Then just enter
pip install pyinstaller
And that's it.
The simplest way to use it is by entering on your command prompt
pyinstaller file_name.py
For more details on how to use it, take a look at this question.
There is an open source project called auto-py-to-exe on GitHub. Actually it also just uses PyInstaller internally but since it is has a simple GUI that controls PyInstaller it may be a comfortable alternative. It can also output a standalone file in contrast to other solutions. They also provide a video showing how to set it up.
GUI:
Output:
Alternatively use pyinstaller directly:
pip install pyinstaller
pyinstaller filename
I can't tell you what's best, but a tool I have used with success in the past was cx_Freeze. They recently updated (on Jan. 7, '17) to version 5.0.1 and it supports Python 3.6.
Here's the pypi
https://pypi.python.org/pypi/cx_Freeze
The documentation shows that there is more than one way to do it, depending on your needs.
http://cx-freeze.readthedocs.io/en/latest/overview.html
I have not tried it out yet, so I'm going to point to a post where the simple way of doing it was discussed. Some things may or may not have changed though.
How do I use cx_freeze?
Now you can convert it by using PyInstaller. It works with even Python 3.
Steps:
Fire up your PC
Open command prompt
Enter command pip install pyinstaller
When it is installed, use the command 'cd' to go to the working directory.
Run command pyinstaller <filename>
I've been using Nuitka and PyInstaller with my package, PySimpleGUI.
Nuitka
There were issues getting tkinter to compile with Nuikta. One of the project contributors developed a script that fixed the problem.
If you're not using tkinter it may "just work" for you. If you are using tkinter say so and I'll try to get the script and instructions published.
PyInstaller
I'm running 3.6 and PyInstaller is working great!
The command I use to create my exe file is:
pyinstaller -wF myfile.py
The -wF will create a single EXE file. Because all of my programs have a GUI and I do not want to command window to show, the -w option will hide the command window.
This is as close to getting what looks like a Winforms program to run that was written in Python.
[Update 20-Jul-2019]
There is PySimpleGUI GUI based solution that uses PyInstaller. It uses PySimpleGUI. It's called pysimplegui-exemaker and can be pip installed.
pip install PySimpleGUI-exemaker
To run it after installing:
python -m pysimplegui-exemaker.pysimplegui-exemaker
The best and easiest way is auto-py-to-exe for sure, and I have given all the steps and red flags below which will take you just 5 mins to get a final .exe file as you don't have to learn anything to use it.
1.) It may not work for python 3.9 on some devices I guess.
2.) While installing python, if you had selected 'add python 3.x to path', open command prompt from start menu and you will have to type pip install auto-py-to-exe to install it. You will have to press enter on command prompt to get the result of the line that you are typing.
3.) Once it is installed, on command prompt itself, you can simply type just auto-py-to-exe to open it. It will open a new window. It may take up to a minute the first time. Also, closing command prompt will close auto-py-to-exe also so don't close it till you have your .exe file ready.
4.) There will be buttons for everything you need to make a .exe file and the screenshot of it is shared below. Also, for the icon, you need a .ico file instead of an image so to convert it, you can use https://convertio.co/
5.) If your script uses external files, you can add them through auto-py-to-exe and in the script, you will have to do some changes to their path. First, you have to write import sys if not written already, second, you have to make a variable for eg, location=getattr(sys,"_MEIPASS",".")+"/", third, the location of example.png would be location+"/example.png" if it is not in any folder.
6.) If it is showing any error, it may probably be because of a module called setuptools not being at the latest version. To upgrade it to the latest version, on command prompt, you will have to write pip install --upgrade setuptools. Also, in the script, writing import setuptools may help. If the version of setuptools is more than 50.0.0 then everything should be fine.
7.) After all these steps, in auto-py-to-exe, when the conversion is complete, the .exe file will be in the folder that you would have chosen (by default, it is 'c:/users/name/output') or it would have been removed by your antivirus if you have one. Every antivirus has different methods to restore a file so just experiment if you don't know.
Here is how the simple GUI of auto-py-to-exe can be used to make a .exe file.
PyOxidizer can be an option here. It's pretty popular with 3.3k stars on Github. Its documentation says
PyOxidizer is capable of producing a single file executable - with a copy of Python and all its dependencies statically linked and all resources (like .pyc files) embedded in the executable. You can copy a single executable file to another machine and run a Python application contained within. It just works.
While I'm not sure if it is capable of producing .exe file PyOxidizer definitely helps with packaging and distribution.
I'm trying to get sublime to highlight smalltalk .st files but am running into some trouble.
A quick search found this package, but after adding the repository like it says in the README, I don't see the package that its supposed to add when doing Package Control: install package.
I also tried looking into this one but am completely lost when it says This syntax file can be converted to .tmLanguage using PackageDev 'Convert to PList'. Place the converted file in Packages/Smalltalk/Smalltalk.tmLanguage and reopen any .st file.
Can anybody help me out please? I'm running ST3 on MacOSX.
The installtion instructions using Package Control did not work for me either, but you can take the language file, Smalltalk.tmLanguage, from Smalltalk syntax for Sublime Text 3 and use the manual installation instructions you cited:
Place the file in Packages/Smalltalk/Smalltalk.tmLanguage
As you asked about macOS, on macOS this means:
/Users/<your user name>/Library/Application Support/Sublime Text 3/Packages/Smalltalk/Smalltalk.tmLanguage
The Library folder might be hidden by default. Use the Terminal or Finder's Go ▶︎ Go To Folder… to access it.
For Smalltalk/X you can download a highlighting package at - sublime highlighting for smalltalk/X called Smalltalk.sublime-package.
You can copy it to the path provided by #MartinW above.
I have been trying to follow Dan Bader's setup and he uses SublimeLinter with Flake8 and Anaconda Plug-in (not the distro). The functionality I can't achieve is the docstring popup and I noticed it is because my Sublime Text 3 is not noticing my Python3. I installed Python3 via homebrew.
which python3
/usr/local/bin/python3
This is what I want to achieve:
This is what I am actually getting:
On the settings for Anaconda plug-in in Sublime Text 3 you can either but the full path or just Python3 (according to most comments I have seen). But the reality is that God knows what Sublime Text 3 actually has for it's path. Some people mentioned that lanuching sublime from the commmand line would inherit you bash path but that did not work either. So in summary I get an error if I use just python3 in the settings and if I used the full path it just doesn't work.
On Anaconda.sublime-settings
{
"python_interpreter": "python3",
}
Error with the above settings:
On Anaconda.sublime-settings, when using full path like below, nothing happened.
{
"python_interpreter": "/usr/local/bin/python3",
}
I am trying to install the Local History package in Sublime 3. I am behind a proxy and so far have not been able to get package control to work so I am installing the package by pulling the repo into my packages directory.
When I installed it the first time I had Sublime Text 3 open and was surprised to see that the Local History commands appeared with out a restart. However, they did not seem to work so I restarted Sublime Text. Package gone.
I have reinstalled it, and stopped and started Sublime multiple times and for whatever reason everytime Sublime starts it removes the entire Local History package from my packages directory.
I have several packages installed in Sublime Text 3 and they all work without issue. This is the first time I have encountered this issue. Any ideas what may be going on?
Go to Preferences -> Settings-User and check if Local History is listed under ignored_packages. If that's the case the package fails to load. Normally deleting Packages/User/Package Control.cache directory solves the problem.
I've updated to the most recent version of Package Control for Sublimetext 3 via Git, but none of the commands work. The menu items are still present, strangely enough. When I open the log with Ctrl+`, I see this error:
ImportError: No module named 'Package Control.package_control.add_repository_channel_command'
How can I get it to work again?
Apparently the Package Control .sublime-package file is outdated, and in this case, referencing a python module that has been moved to a different python package (from package_control to package_control.commands).
This can be easily fixed by deleting Installed Packages/Package Control.sublime-package.
I use sublime text 3
From this site, I Follow these steps:
Go to http://wbond.net/sublime_packages/package_control/installation
& copy the long command there.
Open the Sublime Text 2 console by
pressing Ctrl+.
Paste the command you copied into the Sublime Text
console.
Press Enter.
After Package Control installs, restart
Sublime Text.
Then I got the error like that.
I have tried :
check ignored_packages on set but I found nothing.
Download package manager and copy it to Installed Packages, but not works.
Then I update my sublime to the newest version, then the error is gone.
That is my tips, you should try one of the steps, like what I have tried.