Python GUI Tkinter is not including all libraries or modules to use - python-3.x

I am using Pycharm version: Pycharm Community Edition 2017.1 on Windows 7 64 bit edition, and my environment variables are set as below:
PYTHONPATH: C:\Users\vinsow\AppData\Local\Programs\Python\Python36-32\Lib;C:\Users\vinsow\AppData\Local\Programs\Python\Python36-32\DLLs;C:\Users\vinsow\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6;
PATH: C:\Users\vinsow\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\vinsow\AppData\Local\Programs\Python\Python36-32\;C:\Tcl\bin;C:\Program Files\Java\jdk1.8.0_60\bin;%PATH%
CLASSPATH: C:\Program Files\Java\jdk1.8.0_60\bin;C:\Program Files\Java\jre1.8.0_60\bin;.
When I open a new python file using pycharm and type in:
import tkinter this works
Whereas :
tkinter.[functions popup] would display very few options:
as in image, Looks like I have to update the path variable or either some things to change in my Pycharm IDE. I am a newbie for a tkinter GUI programming.

You have a file named tkinter.py, so it's importing that file rather than the tkinter module. rename tkinter.py to something else.

Childish Mistake.
Your file is named tkinter.py which if you know is the same as the Module tkinter when you type import tkinter.
So What you are doing is;
while 3>2:
os.starfile('/pathtoyourfile')
it is an Infinite Loop going on.
When I was learning python and learning to send emails i named my file email.py and because of that my file was failing try to name you files as adrgdt.py something Unique so you dont run into this error again
I hope this helps.

Related

Why does Tkinter work in the terminal but not in Pycharm?

Using Pycharm on Linux mint.
I installed the "future" package for the python interpreter which I'm using. Heres the script.
from tkinter import *
top = Tk()
top.mainloop()
Didn't work. It returns "ModuleNotFoundError: No module named 'tkinter'". Tkinter is infact installed. "python3 -m tkinter" confirms it. And when I compile the same code in the terminal, it displays.
As Bryan says, you're probably not using the Python version you think you're using. PyCharm tends to install its own version of Python. Once you have more than one version of Python installed, things get trickier.
To see what's happening, try running this script:
import sys
print(sys.executable, sys.version)
Or run those similar commands from the command line. That should help clarify matters.
The sys.executable will show you the full path to your Python executable. Great for seeing where the used Python installation is located.
I don't use Python on Linux, but perhaps one of your Python installations is version 2, in which case you would need to use:
from Tkinter import *
which is another way to confirm that the Python is version 2 rather than 3. If this is the case, you'll want to move to Python 3. I don't think anyone writes new projects in Python 2 anymore. It's defunct, purely legacy.
It's also possible that Python is installed on Linux without Tkinter. There are other posts on how to install Tkinter on Linux. For instance, you can check out ImportError: No module named 'Tkinter'
Thanks guys for the help I really appreciate it. But I found out the problem was because of Linux Mint's Software Manager. I initially downloaded pycharm using said software manager but it didnt work which is why I created the post. Then I deleted it, and downloaded pycharm through the tar.gz file from the jetbrains website. After doing that, it seems to work.

Python 3.6 cx_freeze ModuleNotFoundError: No module named Tkinter

I froze a python 3.6 program with cx_freeze, and it worked just fine. But as soon as I tried to run it, I got this error message.
Does anyone know what to do? Please help!
try using
import tkinter
(small 't' instead of capital)
Try checking the dir names in the 'lib' folder (in my case it was 'build\exe.win-amd64-3.6\lib'). I had a similar issue (without the 'ImportError: DLL load failed...') and found that the 'lib' directory contained a "Tkinter" folder. Changing its name to lowercase 'tkinter' did the trick and made the .exe run just fine.
If you read the error more clearly, it stated in a comment that if importing _tkinter failed, your computer isn't configured to use tkinter. You should download tk and ttk to make it work.
And According to http://wiki.python.org/moin/TkInter :
If it fails with "No module named _tkinter" or "Tkinter", your Python configuration
needs to be modified to include this module (which is an extension
module implemented in C). Do not edit Modules/Setup (it is out of
date). You may have to install Tcl and Tk (when using RPM, install the
-devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in
the default locations, simply rerunning "make" should build the
_tkinter extension.

use nodebox as a module for python 3.5

I'm trying to import everything from nodebox.graphics into my python 3.5 code but I get errors:
ImportError: No module named 'bezier'
To mention, this module exists in nodebox/graphics. As I searched in python documentations, I have to add the nodebox and pyglet folders into the directory of my code but that did not work.
I also didn't succeed in adding them to system directories.
How can I solve the problem and run my code properly?
P.S. I'm currently using ubuntu 16.04 if it matters.
I had the same error. Placing all the .py files except (and this is important) the __init__.py file in the main libraries folder fixed it for me. The final path should look like ~/lib/python3.5/site-packages/bezier.py

Xlwings - Issue with running on 64-bit python? [duplicate]

I am using python 3.4 on windows 7. In order to open a doc file I am using this code:
import sys
import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = 0
word.Documents.Open("MyDocument")
doc = word.ActiveDocument
I'M not sure why is this error popping up every time:
ImportError: no module named win32api
Although I have installed pywin32 from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
and I have also checked the path from where I am importing. I have tried reinstalling pywin32 as well but that doesn't remove the error.
Try to install pywin32 from here :
http://sourceforge.net/projects/pywin32/files/pywin32/
depends on you operation system and the python version that you are using. Normally 32bit version should works on both 32 and 64 bit OS.
EDIT: moved to https://github.com/mhammond/pywin32/releases
This is a bug in the library itself, probably they used a different python implementation for creating this.
What they are trying to import is the site-packages\win32\win32api.pyd file, but the win32 folder is not in the path that python searches in, but site-packages is.
Try to replace the import win32api (inside win32com\__init__.py) to from win32 import win32api
I encountered the same error yestoday with Python 3.6.1 on Windows 7, and resolved it by "pip install pypiwin32".
Had the same error trying to import win32com.client (using Python 2.7, 64-bit). I agree with TulkinRB, there seem to be path issues, but the fix suggested did not work for me, since I also could not import win32.
Perhaps my fix will also work in Python 3.4.
Eventually, installing the .exe from SourceForge as an administrator (as suggested in Rina Rivera's answer here) allowed me to import win32com.client from IDLE, but not when I executed the script I was originally trying to run.
In the end, I discovered 3 differences in the sys.path that had been extended when I installed as admin and opened IDLE, but were not applied when executing a script. By extending the sys.path in my script, I was able to get rid of the import errors when I executed it:
import sys
sys.path.extend(('C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin'))
Finally, if you want more than a temporary fix, the sys.path could be permanently extended by establishing IDLESTARTUP or PYTHONSTARTUP variables (as described here and here).
You can create the __init.py file inside the win32 folder and then go inside the win32com folder and change its __init__.py file, where it is import win32api, change to from win32 import win32api
I ended up debugging and copying and pasting the necessary files into the appropriate folders. It's a work-around until the bug is fixed, but it works.
from https://github.com/mhammond/pywin32/issues/1151#issuecomment-360669440
append the 'pypiwin32_system32' path to your system PATH,
in a script this can be done like:
import os
sitedir='C:/where_ever/'
os.environ["PATH"]+=(';'+os.path.join(sitedir,"pypiwin32_system32"))
...
from powershell
$env:PATH="$PATH;C:\where_ever\pywin32_system32";
python.exe ...
for help on site dir, see What is python's site-packages directory?

Hide console window with Tkinter and cx_Freeze

I am using cx_freeze to freeze a tkinter app. When I run the exe I get a wonderfully USELESS console window along with my tkinter GUI.
I would like to remove/hide this useless black window.
I've seen threads that suggest the following:
root = tkinter.Tk()
root.withdraw()
The above code does the opposite of what I want. It hides my GUI, while the useless black window remains. I would like it to be the other way around.
I remember reading somewhere that on Windows if you specify your file extension as .pyw, it will launch with pythonw.exe (without a console window). Does that work for you?
This question is very similar, but for wxPython and cx_Freeze. Fortunately, it turns out that the appearance of the console can be configured from the build script, rather than source code. Borrowing from the top two answers, the trick is setting the base variable in your cx_Freeze build script:
import sys
from cx_Freeze import setup, Executable
base = None
if (sys.platform == "win32"):
base = "Win32GUI" # Tells the build script to hide the console.
# <The rest of your build script goes here.>
Here is the relevant documentation (although it does not explicitly mention that base controls the console option).
Also, just because it's interesting, an answer to a different question solves the issue of creating a GUI app with or without a console mode option, which I thought was very cool.
Do exactly just like gary said, then:
setup(name="ur package name",
version="ur package version",
description="as above",
executables=[Executable("ur_script.py", base=base)]
This will work cx_Freeze
If using pyinstaller use pyinstaller-gui.py
In Windows command line type
python pyinstaller-gui.py
This will first say "Please use just 'pyinstaller.py'. Gui is not maintained." Change the code l'il bit and you will be able to run this.
It will show pop up a window to select your script and some checkboxex. Check on 'no console(windows only)
That's it. You are done!
Another option: use --noconsole option while building. i.e:
python pyinstaller.py --noconsole yourscript.py
I had the same problem today
What i was using to compile my python programs was py2exe and the fix was very simple modify the setup file as shown below. My interface is written with Tkinter
modify the "setup.py" py2exe script from:
Old Python Code:
from distutils.core import setup
import py2exe
setup(console=['app.py'])
New Python Code:
from distutils.core import setup
import py2exe
setup(windows=['app.py'])
After i did this and reran my setup script the application loaded and did not show the console window. The only thing with this is if you have your application sending print commands to the console window you will not see theme. I hope this helps.
For me using the option --base-name Win32GUI works. Here is an example:
cxfreeze your_python_file.py --base-name Win32GUI --target-dir your_target_dir
I'm assuming by "black window" you are referring to the terminal window. In order to disable this from popping up, save your file as a .pyw extension instead of .py

Resources