py2app does not work with tkinter - python

if I put "import tkinter" in my Python (3.6) file the mac app I get with py2app does not work.
py2app works just fine with other Python files importing other packages (math, time, random etc) only importing tkinter raises this problem

Solved but I'm not sure it should have to work like this.
I think the problem is that Mac works with Python 2.7 (system Python) which raises an error when it gets "import tkinter".
So I installed with Homebrew Python 2.7, redesigned my modules written in P 3.6 ("import Tkinter" etc.) py2app-ed it and everything went fine.

Related

Python 3.5.0b3, 3.5.0rc1: How to make tkinter, Idle, and turtle work on Windows

I have a problem with Python installation on Win 7 Pro.
Python 3.5a2 installs without any problems and work ok.
Python 3.5rc1 installs without any problems but idle doesn't work.
The some was with 3.5b3.
Do you have any idea?
This a a bug in recent 3.5.0 Windows installers.
Symptom: Install 3.5.0rc1 (for instance) on Windows machines without VS2015 installed. Run interactive python and enter import tkinter or run a program that does so (Idle, Turtle, turtledemo, or your own). Get message
Your Python may not be configured for Tk.
Fix: In python35 install directory, find subdirectory /DLLs. In that find subdirectory /MicrosoftVC140.CRT with one file vcruntime140.dll. Move this file up into /DLLs (leaving /MicrosoftVC140.CRT empty). Tkinter should now work.

compiling python to windows exe

I have some supportscript written in python that I thought would be nice to be able to run on client computers. So I was thinking about wrapping them in a GUI and compiling them to an .exe file, which of course seem troublesome.
I gave Pyinstaller a shot but with no luck so I moved forward to nuitka. This works with simple "hello world" scripts, but I need GUI and must be doing something wrong.
My environment is Windows7 x64 with 32-bit Python 2.7 (and 3.4) and Vs2010, 2013 installed.
I've tried different versions of the following command
nuitka --exe --recurse-all --standalone --windows-disable-console --python-version=2.7 helloTk.py
With TK it works on my developer machine, but if I move the Hello.dist folder to another machine nothing happens when I execute it, no errors, nothing.
With QT5 I get a warning from nutika which states something about it's unable to resolve QT imports.
So what am I missing or doing wrong here?
Regards

cx_Freeze app cannot find tk.tcl

I would like to distribute a tkinter app by using cx_Freeze.
I can run the myapp.py from command line.
cx_Freeze creates a folder named "exe.macosx-10.6-x86_64-3.4", and the osx exe works from here.
The osx exe from within myapp.app yields the following error:
`tkinter.TclError: Can't find a usable tk.tcl in the following directories:`
....
This probably means that tk wasn't installed properly.
Here is my stripped-down setup.py
build_exe_options = {"modules": ["tkinter", "time", "requests", "threading", "os"]}
setup(name="myapp",
option={"build_exe": build_exe_options},
executables=[Executable("myapp.py",
base=base)]
)
Edit: I attempted this with python 2.7, and it works. The line "This probably means that tk wasn't installed properly" is likely correct.
I ran into the same problem on mac Yosemite. The system python is 2.7 and I'm using python3. I found that python2.7 build successfully with tkinter but 3.4 does not.
Haven't figured out how to make python3.4 work yet.

Python3.4 Py2exe, error - name 'WinDLL' is not defined

I use Ubuntu, Python 3.4 and try to compile my py scripts to exe using py2exe.
Unfortunately When I try to use command 'build_exe', it generates error!
Could anybody help me to solve it or advise how to compile py project to exe in another way?
Error code:
NameError: name 'WinDLL' is not define.
py2exe is for windows...
On linux you can try PyInstaller:
http://www.pyinstaller.org/
PyInstaller is now able to build Windows executables when running
under Linux. See documentation for more details.
The py2exe module needs to be run from within a command prompt shell (aka Windows terminal) to make a Windows executable, since just like pyinstaller, "they use the OS support to load the dynamic libraries, thus ensuring full compatibility". That's why you get the ''WinDLL' is not defined' error when using the py2exe module in a bash shell.
py2exe works until python-3.4 and pyinstaller works until python-3.7. The latest version at time of writing is 3.8. Use the python module virtualenv from command prompt to get the adeqaute python version running (without replacing your current python set-up), and make your executable file. Here is my answer with code. --> Make sure to add python to your Windows path on install, so you can use the pip and python commands in command prompt. Otherwise you have to replace these commands in my answer for their fullpath, e.g. C:\Users\jakethefinn\python37\pip.exe and C:\Users\jakethefinn\python37\python.exe respectively.
If you install python from Microsoft Store, the files pip.exe and python.exe are automatically added to path.

ImportError: No module named twisted

I'm pretty new to python and twisted and I tried to run a simple twisted script but failed.
My environment:
MacOX 10.7.2 + Python 2.7.1 + Twisted 11.0.0 + eclipse + PyDev
The script called test.py:
from twisted import reactor
reactor.run()
I tried to run it in the terminal and everything works fine.
Then I opened eclipse and created a new PyDev project then adding a py file called test.py and
typed the code above in.
When I tried to run it I got errors like:
Traceback (most recent call last):
File "/Users/user/Documents/workspace/TwistedDemo/test.py", line 2, in <module>
from twisted import reactor
ImportError: No module named twisted
Then I checked the PYTHONPATH and added the "twisted source folder" in the external libraries tab but the errors was still there.(nothing changed)
Hope someone can help me out here, thanks in advance :)
Several things to try here -
Since your env is Mac OSX. I installed commandline tools from Xcode which solved this problem. Xcode 4.4 and later install Command Line Tools
For the sake of completeness. If this on Ubuntu, then apt-get install python-twisted generally works.
from your eclipse put this in your python script -
python -c 'import sys;print sys.path'
This tells all the paths that python looks for when you import something. If you don't find twisted path there then add it to this like so - sys.path.append(twisted_dir_path)
Finally, if all the above does not help. type -p python in a shell will tell you which version you're using; I would mostly be /usr/bin/ or some variant of it.
Then /usr/bin/python2.7 -c 'from twisted.internet.protocol import Factory,Protocol' ought to succeed.
This has happened to me so many times, but I figured out previously. Basically, if you have too many versions of python on your mac, Aptana Studio for some reason gets confused, so make sure that your twisted installation is using the same python as the command line (even though you already added twisted to Aptana). I'll get into more specifics later
Ok, I think this is how you do it:
Grab the python path of the python that has twisted installed correctly, using this
import sys
print sys.path
And just grab the base path, nothing to specific.
Go to Aptana-preferences-PyDev-Interpreter-Python
And then just add a new interpreter (in my case I just called it python1 and set is the first one. If that doesn't work then just set a new PYTHONPATH right below it.
You need to install incremental before twisted
pip install --upgrade incremental
pip install Twisted
This should solve the problem.
Not sure how you installed twisted, did you try easy_install or pip, or install in manually?
If you want to make sure it's installed properly, try opening up a terminal, typing python, and then "import twisted". If it comes back without errors, then it's installed. You might need to set the PYTHONPATH variable to include the source folder.
Then, since you're using pydev in eclipse, you need to refresh your configuration each time you add a new library.
On the mac, this is under preferences -> PyDev -> Interperter-Python
I find it works best to remove my configuration and re-add it, for it to pick up everything. But you can click on new folder (select the folder with the init.py), or the new egg, if it's an easy_install egg (a .egg file is a zip file, if it's unzipped, you'll see a EGG-INFO folder in the subdirectory of the folder you want to select).
You should set the correct PYTHONPATH in Eclipse as following:
right click your project.
select Properties
select pyDev-PYTHONPATH
add your twised in the external libraries

Categories

Resources