I am trying to run this code in pycharm:
import tkinter as tk
root = tk.Tk()
w = tk.Label(root, text="Hello, world!")
w.pack()
root.mainloop()
However it always gives me the following errror:
Traceback (most recent call last):
File "/home/nils/PycharmProjects/rfid/first_test.py", line 1, in <module>
import tkinter as tk
ModuleNotFoundError: No module named 'tkinter'
If I use the same exact code in IDLE, it works perfectly. I just can not figure out how to install/import tkitner (through the project interpreter didnt work). I am using python 3.7 and the newest Linux Mint.
If you could provide me some hints or a solution, it would be very much appreciated :D
Thanks!
Edit: Typing in " import tkinter " in the IDLE shell works fine, however typing in the same in the PyCharm console produces the error above...
Edit2: I solved the problem by completly uninstalling pycharm and installing it again.
If you're here and have issues on macOS Big Sur, and use Homebrew know that tkinter is not included with Python 3.9, and needs to be installed separately.
brew install python-tk#3.9
You can right click it and go to context actions to install or go to the terminal and type,
pip install python-tkinter or sudo apt install python-tkinter!
Related
I am new to python and trying to run code from existing project. I am getting the below error:
Traceback (most recent call last):
File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py", line 2, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
The file is present in the mentioned path.
I see that there are many questions regarding this but nothing seems to provide me with a solution.
I am using the IntelliJ IDEA IDE.
The error message is telling you that File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" is trying to import pytest but fails to find the package. That is, it's not the presence of that file that's failing, but that it can't find pytest in order to import it.
Install pytest using
python3 -m pip install pytest
Change python3 accordingly to use the specific installation of python that you're using in the IDE.
This is because you don't have the needed environment.
Since you use the Pycharm, you can try to install pytest.
https://blog.finxter.com/how-to-install-a-library-on-pycharm/
This worked for me. Repeating here:
Open IntelliJ's settings/preferences
Go to Tools -> Python Integrated Tools
Under Testing...Default test runner: choose pytest
Click the Fix button that appears in the bottom of the panel
I want to use the tkinter module and PyCharm is making it difficult. I am using the Python 3.7 Interpreter, and I have not been able to use it.
I have tried a few things:
pip install tkinter
pip3 install tkinter
sudo apt install tkinter
sudo apt install python-tk
None of these have success
Whenever I use import tkinter, it just returns the error
Traceback (most recent call last):
File "/home/removed/PycharmProjects/Tutorials/GUI.py", line 1, in <module>
import tkinter
ModuleNotFoundError: No module named 'tkinter'
Process finished with exit code 1
Anyone know of a solution?
Always make sure you have the right interpreter selected;
In PyCharm, you can check this by pressing ctrl + alt + s, and navigating to the "project interpreter" tab. Here you can select the different python installations on your system.
This thread might be a little old but I had the same problem for the past 3 days. My solution was as follows (btw I'm running Linux Mint 19 Cinnamon with python3.x):
-Remove PyCharm (I had installed it via Linux Mint's software center)
-Download PyCharm from the JetBrains website.
the "tkinter" module was by installed and recognized by default.
I am having a problem with a python IDE (Sublime) on macos when trying to use ktinter:
I set up a clean mac and installed Python 3.7 via the normal installer (with the box ticked to install tkinter)
The problem I am having now is this: When I write code in Sublime and try to run it within the IDE (Sublime -> Tools -> Build) I get an error message.
Code
import tkinter as tk
tk._test()
Output
Traceback (most recent call last):
File "/Users/christiankoch/Desktop/sys.py", line 1, in <module>
import tkinter as tk
ImportError: No module named tkinter
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/Users/christiankoch/Desktop/sys.py"]
[dir: /Users/christiankoch/Desktop]
[path: /Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]
However, when I just save the file and run it in the terminal everything works fine and I see the test window.
In the terminal
python3 test.py
So ultimately I am confused about different outcomes of the two approaches. When I use Sublime on Windows it works perfectly fine; and even using pyCharm on macos works for tkinter. So I am confused what the problem is.
When you run file.py from the console, the executable as specified in the environment variables is used by default.
In sublime you probably using a build system, that points to another environment/ executable. You should have a look at https://youtu.be/xqcTfplzr7c
And follow the instructions.
I am trying to import the thing in python that will enable me to copy and past things. It seems to have a problem. I later searched my entire C drive for pyperclip and it seems to be not have it at all. How can I go about fixing this? Or am I not looking in the right area? Here is the error:
import pyperclip
Traceback (most recent call last):
File "", line 1, in
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
BTW I'm on windows 10
You seems a new learner for Python. You can try to install that package via pip command. For other problem like how to use pip or which user to run pip, just go to search and solve it by yourself.
So yes you're right. You need to open up cmd prompt. use the cd to change the directory to the one inside Python36\Scripts. Then run the command
pip install pyperclip
The simple import of requests
import requests
can be executes and used in windows shell but the same code says in pycharm:
Traceback (most recent call last):
File "C:/Users/XPS13/PycharmProjects/Testing/Webcrawler_Test.py", line 1, in
<module>
import requests
ModuleNotFoundError: No module named 'requests'
requests was correctly pip installed. Even uninstalling and reinstalling doesn't work.
Any help would be appreciated.
Yeah so this might be a little late but I fixed my problem like this:
Go to Settings/Preferences
Select Project Interpreter
And press the + button on the left side
That + sign
Search for requests
And press Install Package
I am running:
Windows 10
Python 3.7.1
You need to configure the project interpreter in PyCharm:
Go to Settings/Preferences
Select Project Interpreter
Click the little gear and click Add...
Select the appropriate interpreter (whether a virtual environment or system python installation)
Settings top right
'+' above Package table
Search: Requests & highlight in list
Install Package