I am trying to create a plugin for sublime, with it's own GUI. Whatever I try, it seems Tkinter is not getting what it needs to run. Seems it needs some system variables to be set, which are unset when running a Sublime Text Plugin.
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/Tkinter.py", line 1638, in __init__
baseName = os.path.basename(sys.argv[0])
AttributeError: 'module' object has no attribute 'argv'
Is it possible to pick up the required settings from somewhere?
Is there another approach?
As far as I can see sublimetext has its own python interpreter. And it seems to have overridden some of the default functionality. Argv ( The list of shell variables ) is not one of properties available. However are you sure you should be using Tkinter. I am on linux and I don't think Tkinter is available as a library. Not sure but does sublime build over Tkinter . I have not seen a plugin use it. I think you should look at this question.
How to include third party Python packages in Sublime Text 2 plugins
Related
I'm asking help today because I'm new to Tkinter and Pyinstaller (and python in general) and I'm having troubles with it.
I have a simple app working with sqlite, tkinter and pyinstaller to compile all of this in an executable program, the entrance point of my program is a file named main.py
This file calls all the dependancies (like the sqlite module for python, tkinter and my other files like classes etc...)
I made a very simple interface, with a Hello World in a tkinter label and a button to go to page 2 which displays page2 (also in a label), just to see if I'm capable of making it all run and compile all of these pieces together.
I can run it throught my shell executing it like : python main.py and everything is working fine.
But when I run pyinstaller on my linux machine, and start executing the program, nothing appears, my database.db (sqlite database file) is created but I don't have any interface like when I run it with my shell. The thing is getting even worse on windows where, once I've my .exe it just opens a shell and crash after few seconds, not even creating the database.
What I did is I created a 'log file', in which I write the steps of the program.
As you can see on the following picture, the 2 first prints are wrote in my log file (on linux), so I think it crashes when I try to create the window.
If any of you have an idea on what I do wrong, I would really appreciate help :)
General
From the PyInstaller manual:
Before you attempt to bundle to one file, make sure your app works correctly when bundled to one folder. It is is much easier to diagnose problems in one-folder mode.
As the comments suggested, use a catch-all try/except block to log all exceptions to a file. That is probably the best way to see what is really happening. Make sure that the logfile is created in an existing location where you have the necessary permissions.
I would suggest to take advantage of the built-in logging module instead of creating your own. It can e.g. automatically add from which file a log line was created.
IMHO, it is probable that the failures on Linux and ms-windows have completely different causes. You should probably treat them as different issues.
Linux
When you use single file mode, that file is unpacked into a temporary folder, probably somewhere in /tmp. Some Linux distributions mount the /tmp filesystem with the noexec flag. This is incompatible with PyInstaller.
ms-windows
On windows, there are basically two different Pythons; python.exe and pythonw.exe. Basically it is one of the quirks of windows that this is necessary. The latter is for GUI programs like tkinter programs. A tkinter script should not show a cmd window. So I'm guessing that PyInstaller calls your command with python.exe instead of pythonw.exe. From the manual:
By default the bootloader creates a command-line console (a terminal window in GNU/Linux and Mac OS, a command window in Windows). It gives this window to the Python interpreter for its standard input and output. Your script’s use of print and input() are directed here. Error messages from Python and default logging output also appear in the console window.
An option for Windows and Mac OS is to tell PyInstaller to not provide a console window. The bootloader starts Python with no target for standard output or input. Do this when your script has a graphical interface for user input and can properly report its own diagnostics.
As noted in the CPython tutorial Appendix, for Windows a file extention of .pyw suppresses the console window that normally appears. Likewise, a console window will not be provided when using a myscript.pyw script with PyInstaller.
Also, on windows it can matter which Python distribution you're using. I used to be a fan of Anaconda, but lately I've come to prefer the python.org version because it gives me less headaches. On anaconda Python I had the problem that tkinter programs would not launch without showing a cmd window, whatever I tried. Only switching to python.org Python solved that problem.
Say I have a folder called "Family Photos" and I want to automatically run a python program if that folder is selected. How would I go about doing that? Would I just put the code in the folder and it runs automatically?
Edit: I'm on Windows 10
You can use tkinter in python.
Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk.Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one
You can use other GuiProgramming toolkits as well. Follow this_link to know about other gui frameworks.
For how part in Tkinter .Follow this_link
Some unix/linux systems are open source so you could modify the OS behavior to do that, i don't believe windows offer this feature, you probably should create an APP for that
The best solution would be a python scripts that run it self each hour and check if this folder is modified and do something if its, and it will run each time you turn on the computer once
I love sublime text. I know that I can disable autocomplete altogether in the settings, however I just want to disable one of the autocomplete options.
When you type an #property decorator in python you get an autocomplete option called New Property which if selected generates a getter and setter for you. This ends up being more of a pain than a benefit for me. Any ideas about how to remove that autocomplete option?
Sublime Text 2
You can remove Packages/Python/New-Property.sublime-snippet. The Packages directory location depends on the system you are using:
Windows: %APPDATA%\Sublime Text 2\Packages
Linux: ~/.config/sublime-text-2/Packages
OS X: ~/Library/Application Support/Sublime Text 2/Packages
Sublime Text 3
The structure is a little different in Sublime Text 3. Personally I don't use it yet, but this might give you some idea about how to achieve the same result in ST3.
By the way, these solutions are not ideal. When you reinstall or upgrade Sublime Text the snippet will be back. But I'm not aware of any way to disable snippet via user config.
I'm trying to install IDLE2HTML from the following link in order to print from IDLE in color. I use Python 2.7 on a Mac.
I follow the instructions from the readme.txt, but when I reload IDLE nothing has changed. I don't have the Save As HTML option.
In the past I've installed and reinstalled Python a few times.
When trying to find my idlelib folder (as written in the readme instructions), I eventually found it under the path /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
Is my problem that my python is in /System/Library/?
Any ideas please?
I have not tried this extension, but the following may help. When you start Idle, select File / Path browser on the menu. You should see
_ sys.path
|
+ some_path/pythonxy/Lib/idlelib
|
+ some_path/python27.zip # or MAC equivalent
The first path tells you where the new files should be. If you click the +, you will see what file are there. What about IDLE2HTML.py? The next issue is whether you properly edited config-extensions.def. If you wait a few days for 2.7.9 and install it, you can try the new Options / Config-extensions dialog on the menu. That will show whether Idle can read the new information in the .def file. Or you can edit your question, paste in the new material you added, and comment on this answer, and I will take a look. However, given that the extension has been around for years, I presume that the addition in config-extensions.txt is correct.
I suspect that whenever you upgrade Python, config-extension.def will be overwritten and you will have to re-edit it.
If the problem is not a configuration problem with the IDLE2HTML Python IDLE extension like this answer (for the same question) explains about, it may be a problem with the code itself (this has happened with Python 3 IDLE). This can be checked by running IDLE using the Python file that starts it (<PYTHON LIBRARY DIR>\idlelib\idle.py where <PYTHON LIBRARY DIR> is the location of the standard library for the Python installation), in a command line interpreter (use <PYTHON EXECUTABLE DIR>\python.exe where <PYTHON EXECUTABLE DIR is the location of the executable files that start Python). It will launch IDLE and show any errors in the C.L.I..
Quote from Python idlelib module docstring:
Idle includes an interactive shell and editor. Use the files named idle.* to start Idle.
IDLE2HTML real error example:
A common problem is that IDLE2HTML version 2.0 (latest at time of writing) needs a simple code tweak to work with Python 3.x (a fixed version that works as part of the IDLEX Python module had this tweak). File comparison image (left is original file, right is IDLEX version in image); if the Python version is Python 3.x, import Tkinter needs to be changed to import tkinter as Tkinter and import tkFileDialog needs to be changed to import tkinter.filedialog as tkFileDialog:
Edwards suggestion of using the CLI for diagnosis was very useful. It exposed that the cgi.escape attribute does not exist for Python 3.
I changed the IDLE2HTML.py line 74 from "out.append(cgi.escape(content))" to
"out.append(content)" and after a re-boot it all worked!
Later: well almost... better to replace "import cgi" with "import html and then cgi.escape() with html.escape()
If using Win10 you will need super-admin rights to change IDLE2HTML.
A patch issue6075_py3k.patch from bugs.python.org is supposed to fix this problem. In the terminal, I copied the patch file into Idlelib directory where Bindings.py and EditorWindow.py are located and proceeded by typing patch -p2 issue6075_py3k.patch. The patch was successful. I fired up IDLE and I still can't use Breakpoints. What am I doing wrong?
Which version of Python did you patch? And which directory? There are various reason why it might not work. Make sure you are trying to use it correctly. You need to left click on a source line in an IDLE editor window while holding the Control key to set a breakpoint there. Then you'll need to enable the IDLE Debugger, when the Shell window is active, before running the program.
EDIT: The Issue6075 patch does not address the IDLE breakpoints problem (that is for building with Cocoa Tk 8.5, not an issue for the Python 3.1 installer). The breakpoint problem is covered in Issue 10404; download and install the patch for it.