Posts: 20
Threads: 6
Joined: Jan 2018
Jan-25-2018, 10:42 AM
(This post was last modified: Jan-25-2018, 10:45 AM by antonmichel.)
below you can find my code and the output, I am using PyCharm and Python 3.
Thank you,
code :
from tkinter import *
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
root = Tk()
app = Window(root)
root.mainloop() Output
ERROR :
Traceback (most recent call last):
File "C:/Users/Admin/PycharmProjects/untitled/test.py", line 1, in <module>
from tkinter import *
ImportError: No module named tkinter
Posts: 1,298
Threads: 38
Joined: Sep 2016
It almost sounds as if there is a problem with the environmental variables. Are you able to import other modules with out any errors (for instance "import math")?
If not, try typing in the command terminal (not PyCharm):
C:\PATH
You should see at least two entries, "C:Python(3)" and "C:Python(3)\Scripts". Note the actual directory and directory name may be different, depending on where you installed Python.
Just so you know, your script runs fine for me, using Python 3.6.4 and PyCharm.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 4
Threads: 0
Joined: Jan 2018
I agree with @ sparkz_alot. The script works fine on PC too.
Posts: 20
Threads: 6
Joined: Jan 2018
i fixed it finally, the problem was in the project interpreter that python 2 was selected.
anyway, thanks a lot !
Posts: 1,298
Threads: 38
Joined: Sep 2016
That seems strange, do you also have Python 2.x installed?
In any case, glad you fixed your problem. :-)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 20
Threads: 6
Joined: Jan 2018
yes i have version 2 installed as well .. shall i better uninstall it ?
Posts: 1,298
Threads: 38
Joined: Sep 2016
If you have some reason to have v2, then no. If you don't then yes, remove it. It will make your life easier. The v2 was probably the first one you installed, making it the default, which is why PyCharm automatically chose it. Also, if you use 'pip' it will be looking at the v2 library's, not the v3, you would need to use 'pip3' or some variation of that in order to affect the v3 library's. Without a "shebang" line, double clicking a .py (.pyw) file will try and run the file using v2. Similarly, typing "python file_name" will use v2, whereas "python3 file_name" will use v3. Another thing to remember, is if you type "python" in the command terminal you enter the v2 python shell, typing "python3", will invoke the v3 shell.
As you can see, there are some things you need to remember when you have two or more versions installed. As long as you remember the "gotcha's" you'll be fine. Linux users do it all the time as they usually come with v2 and v3 pre-installed.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Posts: 20
Threads: 6
Joined: Jan 2018
i did. thanks for the helpful information!
Posts: 12,047
Threads: 487
Joined: Sep 2016
No need to uninstall python 2.
PyCharm will default to last selected project interpreter unless one is specifically selected.
I have several, and use all without a problem.
When a new project is added, do the following: - file-->settings-->Project Interpreter
- If you see the interpreter that you want in the pulldown, select it and you're done. It will be used from now on for this project.
- If you need to add a new one, click on the gear icon (right of icon)
- select add local
- Choose your environment on left (virtualenv, conda, or System Interpreter)
- Next click on new environment or existing environment
- If new environment, choose (or add) base Interpreter (be careful on virtual environment, do not choose an interpreter that was created by another project unless you are sure this what you want to do, otherwise you will build a dependency).
- in virtual, you can also choose to inherit all site packages (Normally don't do this, or you will dramatically increase the package footprint).
- If not creating a virtual environment, choose existing environment
- Select the Interpreter from pull down, or click ... ad navigate to the desired one, and add it.
Sounds like a lot, but it can do a lot, and ease creation of the virtual environment (if using one), and selection of packages by selection from pulldown and installing here.
|