I keep struggling with importing the pyqtgraph module. It's really only about the import:
pip3 install pyqtgraph is not working.
My code:
from PyQt5 import QtGui
import PyQt5
import numpy as np
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
import pyqtgraph as pg
import time
leaves:
<ipython-input-37-14dc06d126e4> in <module>
31 import numpy as np
32 from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
---> 33 import pyqtgraph as pg
34 import time
35 import sys
ModuleNotFoundError: No module named 'pyqtgraph'
I am guessing that your module gets installed to another Python version than what PYTHONPATH points to.
Try pip3 list -v | grep "pyqtgraph" on Unix-like OSs, or pip3 list -v | findstr "pyqtgraph" on Windows.
The directory location that will be shown will be different to your PYTHONPATH. Set your location to PYTHON3.7 dir and it should solve your problem. See here on how you can do that.
Related
I created a GUI with python and now I want to create an exe file, which can be used on every computer which has not python installed.Im using macOS ...
Is this possible?
The following modules I used:
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QMessageBox
from PyQt5.QtGui import QIntValidator
import pandas
import folium
import numpy as np
import networkx
I am writing an app that needs to work both in Windows and in Linux. I have been developing it in Linux and am just now working on the details to make it work on both platforms. The issue I am running into is with regards to importing other python files from another directory. The app, which runs without issue in Linux (Ubuntu 18.04), has the following folder structure:
- data
- images
- lib
---- configTools.py
---- dbTools.py
---- osciloscopeTools.py
---- peakFindingTools.py
---- poissonTools.py
---- plottingTools.py
---- spacingTools.py
- src
---- config.py
---- interface.py
The program begins with running interface.py. The beginning of the code that I have at the moment is written as follows:
import pandas as pd
import os
import sys
sys.path.append('../lib')
#sys.path.append(os.path.realpath('../lib'))
import platform
import subprocess as subprocess
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget, QVBoxLayout, QFileDialog, QLabel, QCheckBox, QLineEdit, QGridLayout
from PyQt5.QtGui import QIcon, QPixmap
#from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5 import QtCore, QtWidgets
import matplotlib
import time
import sqlite3
matplotlib.use('Qt5Agg')
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
#import os
import matplotlib.pyplot as plt
import math
import numpy as np
import imageio
import csv
# Import local files
import configTools as ct
import dbTools as dbt
import oscilloscopeTools as ot
import peakFindingTools as pft
import poissonTools as pt
import config
import plottingTools as pltools
The issue when running in Windows (Visual Studio 2019) is the block at the bottom where I attempt to import my other python files. An exception is thrown saying "No module named 'configTools'". All of the files in that block are similarly underlined in the IDE, saying "unresolved import ___" where ___ is the filename of each. My best guess is that the line executing "sys.path.append('../lib')" is not accomplishing the desired effects in Windows. Permanently altering environment variables is not a good option for me since this app needs to be portable once it's done. It works fine in Linux, so I am under the impression that this is valid Python, but I cannot find the correct way to accomplish the task at hand in Windows. Further, I really do not want to put everything in the same folder; even if that would be the easiest thing for the python files, the data and images folders will populate with hundreds of files over the course of execution, and I suspect that I will run into similar problems when trying to read and write from those folders.
I have an error which's complete form is
MatplotlibDeprecationWarning: The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3
I converted my script into executable file. After conversion, it never opened. When I execute script with IDEs(VS Code, Linux shell, and Spyder), it works. Somehow it does not open after I converted it to exe. I wrote some lines to avoid from this error, but simply it did not work. For example;
Python/matplotlib : getting rid of matplotlib.mpl warning
I used pyinstaller and auto-py-to-exe to convert my script into exe.
This is the beginning of my code:
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt, QDate, pyqtSlot
from PyQt5.QtGui import QIcon
from datetime import datetime
import calendar
import sys
import numpy as np
import pandas as pd
from scipy.signal import find_peaks
import os
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.dates as mdates
matplotlib.use('Qt5Agg')
myFmt = mdates.DateFormatter('%d')
It is very long to put all the code here. Thank you very much for your interest.
Arda, I've found out after trial and error that pyinstaller has a conflict with the latest version of matplotlib. In order to produce an executable of your script with pyinstaller you should downgrade matplotlib to 3.2.2 version. I have also found some problems with the latest (1.19.4) version of numpy which went away when I downgraded numpy to 1.19.3.
You can check my repository
https://github.com/matiasleoni/COVID19_plotter
where I created a simple script to plot COVID19 global data using matplotlib package. After many failed attempts I was also able to create an executable version of it as I described above (see also the README.md of that repository).
The following code is the module I used in my pyqt widget, but after I use pyinstaller to build exe file, the file size is 233MB large.
How can I reduce the file size?
I tried to create a new virtual environment, but there is no improvement, and I also tried to add excludes=['mkl','whl'] in my pyinstaller spec file, but no improve as well.
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication, QFileDialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import Qt, pyqtSignal, QEvent
import sys
from glob import glob
from numpy import array as nparray
from PIL.Image import open as imopen
from win32gui import GetWindowText, GetForegroundWindow
from MainWindow import Ui_MainWindow, resource_path
from qimage2ndarray import array2qimage
from shutil import move
from os import makedirs, chdir, getcwd
from os import path as ospath
MainWindow is the UI code I build with qtdesigner, the module it use is :
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QStatusBar
from PyQt5.QtCore import QRect, Qt, QSize, QMetaObject, QCoreApplication
from PyQt5.QtGui import QFont, QIcon, QPixmap
import sys
from os.path import join, abspath
For my app I was able to reduce size from 80mb to 15mb
Here is what I did :-
First Use pyinstaller in one directory mode
The created folder has a lot of garbage and unrequired stuff so first delete the DLL files which you know you have not used in application.
Then for rest of files use hit-and-trial method, delete one file and see if app is still working properly, if not then restore that file and try with some other file.
After you are done, use UPX (in lzma mode) on all .pyd files.
Most of DLLs can also be compressed with UPX except some (like VCRUNTIME.dll), so you will have to do hit and trail for DLL files too.
Finally you can compress any images (if any) on your app.
Done (◠‿◕)
Finally I reduce my exe file size from 233MB to 64MB by solution provided here :
Create a new conda environment pyinstaller-env
install numpy with conda install conda-forge::numpy "blas=*=openblas"
Switch environment to pyinstaller-env and package my QT application.
I do not program on Python, so I don't know what the problem is.
I just can't start the program from the command line, this is displayed:
Here is code __init__.py
import os
import sys
from PyQt4 import QtGui, QtCore
from pynfb.experiment import Experiment
from pynfb.io.xml_ import xml_file_to_params
from pynfb.settings_widget.general import GeneralSettingsWidget
from pynfb.settings_widget.inlet import InletSettingsWidget
from pynfb.settings_widget.protocol_sequence import ProtocolSequenceSettingsWidget
from pynfb.settings_widget.protocols import ProtocolsSettingsWidget, FileSelectorLine
from pynfb.settings_widget.signals import SignalsSettingsWidget
from pynfb.settings_widget.composite_signals import CompositeSignalsSettingsWidget
from pynfb.settings_widget.protocols_group import ProtocolGroupsSettingsWidget
static_path = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/static')
class SettingsWidget(QtGui.QWidget):
You need to install PyQt4 first: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4.
Download the correct file corresponding to the version of your python, e.g. PyQt4‑4.11.4‑cp37‑cp37m‑win_amd64.whl then install by using pip (https://pip.pypa.io/en/stable/installing/)
pip install PyQt4-4.11.4-cp37-none-win_amd64.whl