How to install and use PyQt5 in Linux - python-3.x

In Ubuntu I installed PyQt via pip
pip3 install PyQt5
However, my script still says:
Traceback (most recent call last):
File "/media/storage/Python/my_app.py", line 11, in
from mainwindow import * File "/media/storage/Python/mainwindow.py", line 4, in
from PyQt5 import QtCore, QtWidgets
ImportError: No module named PyQt5
Then I tried from terminal:
sudo apt-get install python3-pyqt5
and got that it is installed:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-pyqt5 is already the newest version (5.7+dfsg-5).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
How to convince PyCharm 2017.1 to use PyQt5? I just realized it works if I run it from terminal:
python3 my_script.py

The problem here is that you need to set the correct interpreter in PyCharm.
To do this you can go in
Settings -> Project -> Project Interpreter
and here choose the correct one in the select at the top of the window.
After this you should see the PyQt in the list below. Then click on Apply and try to run again your script.

Related

Is tkinter renamed in Python 3.9.0b3?

I just upgraded to python 3.9 (Earlier I had python 3.8.2)
I was working on a project where I had to use tkinter module.
Everything worked fine in Python3.8.2
But after upgrading to Python3.9 , I get this error :
The error is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/tkinter/__init__.py", line 37, in
<module>
import _tkinter # If this fails your Python may not be configured for
Tk
ModuleNotFoundError: No module named '_tkinter'
So anyone knows how to fix this ?
P.S :
I have tried using
sudo apt install python3-tk
It only gives this message :
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-tk is already the newest version (3.8.2-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Edit :
I found 2 pip installed on my system namely : pip3 and pip3.9 (I don't know how)
One is familiar pre existing pip3
When I do pip3 list
Package Version
------------------------ --------------------
aiohttp 3.6.2
apturl 0.5.2
astroid 2.4.2
async-timeout 3.0.1
attrs 20.2.0
autopep8 1.5.4
#(And many more...)
But when I do pip3.9 list , I get only 2 modules installed:
Package Version
---------- -------
pip 20.2.3
setuptools 41.2.0
Okay , Got it what was wrong (Thanks to #acw1668 ). I installed python 3.9 from the source without having dependencies (tk-dev and tcl-dev)
So the first thing I did was uninstalling Python3.9
Then reinstalled it using this method (From deadsnakes ppa)
Then in terminal , run sudo apt install python3.9-tk
Now everything works fine.
Thanks to #Noah-J-Standerson for suggesting this method

can't make a python project into an executable because path issues?

I'm trying to turn my python project into .exe
I used : pyinstaller --onefile main.py
Then I moved the main.exe into the original file to be sure it can access all the dependencies.
When I run the main.exe, I get an error, failed to execute script main.
I typed cmd in the directory of the python project, and tried python main.py
It gave me this error :
Traceback (most recent call last):
File "main.py", line 3, in <module>
from PyQt5 import QtWidgets, QtCore
ModuleNotFoundError: No module named 'PyQt5'
Even though every module are installed, why is it telling me that?
Thank you.
You haven't installed pyqt5.
Try pip install pyqt5 or pip3 install pyqt5
for linux
sudo apt install python3-pyqt5

No module named 'info' on fresh Python 3 installation

I did a fresh python3 installation on OSX via homebrew:
brew install python3
Then I created a virtual environment for my project and installed scipy and scikits.samplerate:
virtualenv -p /usr/local/bin/python3 pythen_env
pip install scipy
pip install scikits.samplerate
However, when I try to import a function from scikits.samplerate, I get the following error:
>>> from scikits.samplerate import resample
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/__init__.py", line 4, in <module>
from info import __doc__
ModuleNotFoundError: No module named 'info'
Info happens to be the first module from the package itself that is imported in __init__.py.
Strangely, the module info.py exists in /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/:
ls /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/
__init__.py setup.py tests __pycache__
info.py setuphelp.py version.py
The error also happens when I try the same without virtualenv, as well as for other packages. How could I start to debug this issue?
The problem seems to be that the package scikits.samplerate does not support Python 3.X (see issue). However, there is a fork which supports Python 3.X. You can install it via
$ pip install git+https://github.com/gregorias/samplerate.git
As always: people can make anything they like in repositories. I did not check which changes gregorias made.
the git version does support py3
https://github.com/cournape/samplerate
(merged the PR from #gregorias)
I should find the time and procedure to update pypi too...

python pygame library issue, ImportError: No module named 'pygame.base' [duplicate]

When I download pygame-1.9.2b8-cp36-cp36m-win32.whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame I turn it into zip, take the headers in the pygame-1.9.2b8.data folder into pygame34/include/pygame and I put the other pygame file from the zip in the site-packages folder together with pygame-1.9.2b8.data as any tutorial shows, I always get this error:
Traceback (most recent call last):
File "C:/Users/andsa/PycharmProjects/THIS WORKS ANDREAS/Games.py", line 1, in <module>
import pygame
File "C:\Python34\lib\site-packages\pygame\__init__.py", line 141, in <module>
from pygame.base import *
ImportError: No module named 'pygame.base'
EDIT: I use python 3.4.5, I have tried both python and pygame 64 and 32 bit but i still get this error
This error bugged me for months, what i did was:
Uninstalled the package
pip3 uninstall pygame
Purged the pip cache
pip cache purge
Finally...Reinstalled pygame using pip3
pip3 install pygame
Worked like a charm :)
Use pip3 tool to reinstall the pygame python module:
C:\Python373\Scripts>pip3 uninstall pygame
C:\Python373\Scripts>pip3 install pygame
Then install it:
C:\Python373\Scripts>pip install pygame-menu==2.0.1
You probably have python installed for 32-bit. Uninstall and the install the 64-bit version. After that,
pip3 uninstall pygame
pip3 install pygame
try usin pip3 install pygames
to install pygames
pip3 install pygame
SUBLIME TEXT SOLUTION
OBS: THE REASON MOST GUI FRAMEWORKS DO NOT WORK ON SUBLIME IS BECAUSE OF THIS ONE LITTLE DETAIL HERE
Create a new build system:
In Sublime go to >> Tools
Tools >> Build System
Build System >> New Build System
DELETE EVERYTHING CONTAINED IN THIS NEW FILE AND ADD THIS PIECE OF CODE:
{
"cmd": ["/usr/local/bin/python3.8", "-u", "$file"],
"file_regex": "^[]*File \"(...*?)\", line ([0-9]*)"
}
ATTENTION: DO NOT CHANGE THE CURRENT DIRECTORY YOU ARE ON, WHICH IS THE
USER ONE.
SAVE IT AS Python3.8.sublime-build
In Sublime go to >> Tools
Tools >> Build System
Mark the Python3.8 you have just created
Voila!
P.S I Saved mine as 3.7 but it works the same, as long as the code inside the file is 3.8, or whatever version you have on your machine currently.

importing pygame on python3 on virtualenv cause ImportError

I have python3.3.1 on ubuntu lucid,which I invoke thru virtualenvwrapper ' .I wanted to learn pygame,so I used pip to install it.Before that I installed the sdl and smpeg dev libraries
me#ubuntu: sudo apt-get install libsdl1.2-dev
...
me#ubuntu: sudo apt-get install libsmpeg-dev
...
me#ubuntu: workon envpy331
(envpy331)me#ubuntu:~$ pip install pygame
Downloading pygame-1.9.1release.tar.gz (2.1MB): 2.1MB downloaded
Running setup.py egg_info for package pygame
WARNING, No "Setup" File Exists, Running "config.py"
Using UNIX configuration...
Hunting dependencies...
SDL : found 1.2.14
FONT : not found
IMAGE : not found
MIXER : not found
SMPEG : found 0.4.5
PNG : found
JPEG : found
SCRAP : found
PORTMIDI: not found
PORTTIME: not found
....
Continuing With "setup.py"
Successfully installed pygame
Cleaning up...
Then I tried to import pygame and this caused an import error
(envpy331)me#ubuntu:~$ python
Python 3.3.1 (default, Apr 19 2013, 11:41:37)
[GCC 4.4.3] on linux
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/.virtualenvs/envpy331/lib/python3.3/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: /home/me/.virtualenvs/envpy331/lib/python3.3/site-packages/pygame/base.cpython-33m.so: undefined symbol: PyCObject_FromVoidPtr
Any idea how to correct this?
Pygame has not been entirely ported to Python 3, only some of the modules. If you use Python 2.7 everything should work. I recently had the same problem. Some suggested using individual modules of Pygame with Python 3 but this may be tricky to set up.
I know this is and old question but since I spent some time on the problem, this is the easiest way to install pygame for python3.4 in its own virtual environment:
sudo apt-get build-dep python-pygame
sudo apt-get install python3-dev libswscale-dev libavformat-dev virtualenvwrapper
echo "export WORKON_HOME=~/.venvs" >> ~/.bashrc
echo ". /usr/share/virtualenvwrapper/virtualenvwrapper.sh" >> ~/.bashrc
. ~/.bashrc
The above you do once. The following you repeat for each new environment:
mkvirtualenv -a ~/your/project/path -p /usr/bin/python3.4 your_project_name
pip install hg+http://bitbucket.org/pygame/pygame
This should download and compile the right pygame version (with bunch of warnings, yet working). Tested on Ubuntu GNOME 14.04 and 14.10.
Each time you start working on a given project or wish to switch between projects:
workon your_project_name
The project name will appear in the prompt. And when you want to finish and go back to your system-wide environment:
deactivate

Resources