I am having issues with properly installing Tkinter and PyQt5 in my Ubuntu environment (I have a Windows computer with Ubuntu activated and linked to PyCharm).
I have tried installing via the packages installer inside PyCharm and via codes in the Ubuntu terminal itself (like apt-get install and pip install). Even though some installations seemed to work, the modules are not being loaded properly. In fact, Tkinter doesn't even show up as a download option inside PyCharm (I only found "tk" but it doesn't seem to work the same).
After trying a bunch of stuff, these are the messages I get when trying to load these packages:
Traceback (most recent call last):
File "part3_displaying_table.py", line 18, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: bad magic number in 'PyQt5': b'\x03\xf3\r\n'
Traceback (most recent call last):
File "part2_visualizing_venn.py", line 24, in <module>
from PIL import Image, ImageTk
File "/usr/local/lib/python3.6/dist-packages/PIL/ImageTk.py", line 28, in <module>
import tkinter
ModuleNotFoundError: No module named 'tkinter'
Any ideas of what might be happening?
P.S. 1: I have the exact same repositories installed in my Windows OS and importing the modules/running the code work completely fine.
P.S. 2: I need to install those in the Linux environment because I will need to call a program in my code that is not compatible with Windows; as a consequence I will have to run the whole code in my Ubuntu environment.
From https://wiki.python.org/moin/TkInter:
Step 2 - can Tkinter be imported?
Try the correct command for your version at the Python prompt:
>>> import Tkinter # no underscore, uppercase 'T' for versions prior to V3.0
>>> import tkinter # no underscore, lowercase 't' for V3.0 and later
If it works, go to step 3.
If it fails with "No module named Tkinter", your Python configuration needs to be changed to include the directory that contains Tkinter.py in its default module search path. You have probably forgotten to define TKPATH in the Modules/Setup file. A temporary workaround would be to find that directory and add it to your PYTHONPATH environment variable. It is the subdirectory named lib-tk of the Python library directory (when using Python 1.4 or before, it is named tkinter).
Related
At the top of my python code, I put import pygame as usual, and have installed the module on my computer. So why do i get this when running my code? I have already tried deleting pygame and reinstalling it and it has not worked. The files are on my computer. Can anyone help me?
Traceback (most recent call last):
File "C:\Users\<myuser>\Documents\RPG\main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I think you might not have added the python path when you installed python. If you're using windows, search for Edit the system environment variables. Click on Environment variables, in the system variables section, double click on path -- and add the path of your python software.
ex: C:\Program Files\Python310\Scripts\ & C:\Program Files\Python310*
Currently I cannot import package installed in virtual environment:
Traceback (most recent call last):
File "/Users/glada/GIT_REPOS/autoflux/main.py", line 5, in
import cx_oracle
ModuleNotFoundError: No module named 'cx_oracle'
Imports in python are sometimes a bit tricky because it depends on how you call a line of code. Do you call the import from the python REPL input?
>>> import cx_oracle
Do you call the line of code from inside a script?
$ python myscript.py
Do you run the script as a module?
$ python -m myscript
Also a folder structure would be helpful. Do you use virtualenv? Maybe you have installed the package to the wrong location (installed in main python installation site-packages and now you are trying to import inside an activated virtualenv)?
There is a brilliant answer on a similar question, which is really descriptive and once I also found very useful to understand imports in python. Maybe this helps you.
I had to uninstall and reinstall python for other reasons.
Right now I downloaded python 3.8.2 through pyenv but running:
import tkinter
The error I get is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cagava/.pyenv/versions/3.8.2/lib/python3.8/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
why is that so? Am I missing some modules in python installation?
Note that I am working on a Mac
I've tried the solution proposed on the issue (Python not configured for Tk) and others suggesting the same method but it didn't solve my problem
Struggling with this myself. For all the talk about the "annual ritual" to include tkinter with Python, it sure isn't well integrated, especially when using pyenv.
I'm about to take the plunge one site suggested: removing pyenv completely, then installing tcl-tk, then compiling a number of post-tcl-tk dependencies that come up after the tcl-tk install, then reinstalling pyenv (which should, supposedly, then add tkinter support - even though tkinter was installed on the default system python of 2.7.16, then reinstalling the versions of Python I've already installed (3.7 and 3.8 and which seem to work for everything but tkinter). Like I said - not well integrated. Were it not for the many comments about how well tkinter has been expanded and maintained I'd be tempted to (and actually, was tempted to) try something else.
Linux Ubuntu and PopOS (Ubuntu derivative) both display the same problem, on two different machines. I'll give the above a try and report back on the fireworks.
I am trying to run python file on my terminal and I get the error of "no module named pyside2"
I tried the to run the code which was already answered on similar type of question. But no changes on my side.
ERROR message:
Traceback (most recent call last)
File "xxx-qt.py", line 31, in <module>
from pyside2 import qtcore
Modulenotfounderror: NO module named "pyside2"
The problem arises because you haven't the module in your environment, you can install it using pip install PySide2
For more about PySide2: https://pypi.org/project/PySide2/
You used all lower-case letters in your PySide2 import statement.
The error message shows that your code imports using lowercase letters instead of mixed case:
NO module named "pyside2"
You probably installed PySide2 using all lowercase letters, pip install pyside2, but your code must import from: PySide2.
I solved this issue by:
1. Repairing my Python installation
2. Deleting the virtual environment
3. Creating a new virtual environment
4. Running pip install PySide2 in the new virtual environment
I had the same problem and solved it with the following way.
Reference from Qt for Python & PyInstaller
Since it has a UI, you use the –windowed option.
The command line to proceed looks like this:
pyinstaller --name="MyApplication" --windowed hello.py
This process creates two directories: dist/ and build/. The
application executable and the required shared libraries are placed in
dist/MyApplication.
To run the application, go to dist/MyApplication and run the program:
cd dist/MyApplication/
./MyApplication
Well there might be one of these two problems:
You have not installed PySide2, In that case you can install it using command pip install PySide2
The second is you have installed the Pyside2 but in one installation and trying to use it from another installation, to tackle with this, Create a virtual environment for your project and install all modules in that virtual environment.
It's always a good idea to create virtual environment for project it will avoid breaking the base env. It avoid such kind of issues
I wish to run a package, openquake; however, it was installed separately from Anaconda, which I am using to run python.
[centos modules]$ which python
~/anaconda2/bin/python
I have set openquake up and I believe it's installed correctly, however, when I try to run my script, I receive the following error:
[centos maxdist]$ python ../script.py
Traceback (most recent call last):
File "script.py", line 12, in <module>
from openquake.hazardlib.source import ComplexFaultSource
ImportError: No module named openquake.hazardlib.source
I was wondering if I need to add a line to my script for it to find the openquake module for it to run successfully? In general, what's the best way to run a python package that is installed outside of the main Anaconda python instance? I am trying to avoid having to re-install openquake for Anaconda, as I was having a little bit of difficulty with that work-around.
Thank you.
If both environments, anaconda and default python that you installed the library for have the same python version, then
import sys
sys.path.append(r'/path/to/package')
from openquake.hazardlib.source import ComplexFaultSource
Check if this works. If the package is compiled for different version, then there will be an error. Also, I would suggest you to use one environment and avoid doing this for the sake of simplicity.