I'm trying to write a simple GUI for a graphing program I am writing, it runs in Idle(Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32) with no problems, but when I try to run in Eclipse, pydev, the script doesn't work.
I opened the console in eclipse and tried to import FigureCanvas(the only error eclipse is showing me) and I got this is the error message I get:
from matplotlib.backends.backend_qt5agg import FigureCanvas
Backend TkAgg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\qt_compat.py", line 198, in <module>
from PySide import QtCore, QtGui, __version__, __version_info__
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'PySide'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 16, in <module>
from .backend_qt5 import (
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\backend_qt5.py", line 18, in <module>
import matplotlib.backends.qt_editor.figureoptions as figureoptions
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
import matplotlib.backends.qt_editor.formlayout as formlayout
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 56, in <module>
from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
File "C:\Users\Daniel\.p2\pool\plugins\org.python.pydev.core_7.1.0.201902031515\pysrc\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backends\qt_compat.py", line 201, in <module>
"Matplotlib qt-based backends require an external PyQt4, PyQt5,\n"
ImportError: Matplotlib qt-based backends require an external PyQt4, PyQt5,
PySide or PySide2 package to be installed, but it was not found.
this is the part of the code that is being run, both on idle(which works) and on eclipse(doesn't work)
# mplwidget.py
from PyQt5.QtWidgets import*
from matplotlib.backends.backend_qt5agg import FigureCanvas
from matplotlib.figure import Figure
class MplWidget(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.canvas = FigureCanvas(Figure())
vertical_layout = QVBoxLayout()
vertical_layout.addWidget(self.canvas)
self.canvas.axes = self.canvas.figure.add_subplot(111)
self.setLayout(vertical_layout)
this is the main function that calles the mpwidget
# ------------------------------------------------------
# ---------------------- main.py -----------------------
# ------------------------------------------------------
from PyQt5.QtWidgets import*
from PyQt5.uic import loadUi
from matplotlib.backends.backend_qt5agg import (NavigationToolbar2QT as NavigationToolbar)
import numpy as np
import random
class MatplotlibWidget(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
loadUi("UI.ui",self)
self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
#self.pushButton_generate_random_signal.clicked.connect(self.update_graph)
self.addToolBar(NavigationToolbar(self.MplWidget.canvas, self))
def update_graph(self):
fs = 500
f = random.randint(1, 100)
ts = 1/fs
length_of_signal = 100
t = np.linspace(0,1,length_of_signal)
cosinus_signal = np.cos(2*np.pi*f*t)
sinus_signal = np.sin(2*np.pi*f*t)
self.MplWidget.canvas.axes.clear()
self.MplWidget.canvas.axes.plot(t, cosinus_signal)
self.MplWidget.canvas.axes.plot(t, sinus_signal)
self.MplWidget.canvas.axes.legend(('cosinus', 'sinus'),loc='upper right')
self.MplWidget.canvas.axes.set_title('Cosinus - Sinus Signal')
self.MplWidget.canvas.draw()
app = QApplication([])
window = MatplotlibWidget()
window.show()
app.exec_()
when I try to run the code in eclipse nothing happens, but whe it runs on idle every thing opens the way I expect
This usually means that some environment variable is not configured the same way in both environments.
Please take a look at the FAQ: http://www.pydev.org/faq.html#MyProgramDoesNotWorkInPyDev to see how to proceed (mainly print the environment/PYTHONPATH on both to check the differences and fix the config on PyDev).
Related
I have been trying to deploy EasyOCR (it's fine if it works on CPU) with FastAPI endpoints such that anyone can use it via https POST request. It runs fine on my local host but when I have been facing challenges in deploying it using pythonanywhere. I added the additional requirements like pip install easyocr, pip install python-multipart==0.0.5.
The following is my code-
import io
import logging
import re
from fastapi import FastAPI, APIRouter, Request, File, UploadFile
from fastapi.responses import FileResponse, StreamingResponse
import easyocr
import PIL
from PIL import Image, ImageOps
import numpy
app = FastAPI()
router = APIRouter()
ocr = easyocr.Reader(["en"])
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("ocr")
#app.get("/")
async def root():
return {"message": "Hello World"}
#app.post("/ocr")
async def do_ocr(request: Request, file: UploadFile = File(...)):
if file is not None:
imgFile = numpy.array(PIL.Image.open(file.file).convert("RGB"))
res = ocr.readtext(imgFile)
# return array of strings
return [item[1] for item in res]
return {"error": "missing file"}
app.include_router(router)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app)
I am getting the error in the logs-
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/somyatomar15/main.py", line 82, in <module>
uvicorn.run(app)
File "/usr/local/lib/python3.10/site-packages/uvicorn/main.py", line 463, in run
server.run()
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
self._run_once()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
handle._run()
File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 77, in serve
await self.startup(sockets=sockets)
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 158, in startup
sys.exit(1)
SystemExit: 1
Traceback (most recent call last):
File "/anaconda2/bin/airflow", line 25, in
from airflow.configuration import conf
File "/anaconda2/lib/python2.7/site-packages/airflow/init.py", line 31, in
from airflow.utils.log.logging_mixin import LoggingMixin
File "/anaconda2/lib/python2.7/site-packages/airflow/utils/init.py", line 24, in
from .decorators import apply_defaults as _apply_defaults
File "/anaconda2/lib/python2.7/site-packages/airflow/utils/decorators.py", line 34, in
from airflow import settings
File "/anaconda2/lib/python2.7/site-packages/airflow/settings.py", line 36, in
from airflow.configuration import conf, AIRFLOW_HOME, WEBSERVER_CONFIG # NOQA F401
File "/anaconda2/lib/python2.7/site-packages/airflow/configuration.py", line 44, in
standard_library.install_aliases()
File "/anaconda2/lib/python2.7/site-packages/future/standard_library/init.py", line 483, in install_aliases
import test
File "/anaconda2/lib/python2.7/test.py", line 9
PATH=$SPARK_HOME/bin:$PATH
^
SyntaxError: invalid syntax
issue with my /anaconda2/lib/python2.7/test.py file ,removed this
now airflow working fine
Importing paramiko throws following exception on Python3.
Traceback (most recent call last):
File "requirements_check.py", line 117, in <module>
import paramiko
File "/usr/local/lib/python3.5/dist-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 90, in <module>
from paramiko.ed25519key import Ed25519Key
File "/usr/local/lib/python3.5/dist-packages/paramiko/ed25519key.py", line 22, in <module>
import nacl.signing
File "/usr/local/lib/python3.5/dist-packages/nacl/signing.py", line 17, in <module>
import nacl.bindings
File "/usr/local/lib/python3.5/dist-packages/nacl/bindings/__init__.py", line 17, in <module>
from nacl.bindings.crypto_aead import (
File "/usr/local/lib/python3.5/dist-packages/nacl/bindings/crypto_aead.py", line 28, in <module>
lib.crypto_aead_chacha20poly1305_ietf_keybytes()
AttributeError: cffi library '_sodium' has no function, constant or global variable named 'crypto_aead_chacha20poly1305_ietf_keybytes'
Does anyone know why?
Try uninstalling & reinstalling PyNaCl:
pip uninstall PyNaCl
pip install PyNaCl
I am using authorize.net python lib for making payment gateway. I am following this link:
https://github.com/AuthorizeNet/sample-code-python
The code is like: PaymentTransactions/charge-credit-card.py
from authorizenet import apicontractsv1 <br>
from authorizenet.apicontrollers import createTransactionController <br>
def charge_credit_card(amount):<br>
"""
Charge a credit card
"""
When I run this file, code throwing this error:
Traceback (most recent call last): File
"C:/development/learning/VueJsLearning/Payment-system/sample-code-python/PaymentTransactions/charge-credit-card.py", line 10, in
from authorizenet.apicontrollers import createTransactionController File
"C:\Python27\lib\site-packages\authorizenet\apicontrollers.py", line
9, in
from authorizenet import apicontrollersbase File "C:\Python27\lib\site-packages\authorizenet\apicontrollersbase.py",
line 11, in
from pip._vendor import requests File "C:\Python27\lib\site-packages\pip_vendor\requests__init__.py", line
83, in
from pip._internal.compat import WINDOWS File "C:\Python27\lib\site-packages\pip_internal__init__.py", line 42, in
from pip._internal import cmdoptions File "C:\Python27\lib\site-packages\pip_internal\cmdoptions.py", line 16,
in
from pip._internal.index import ( File "C:\Python27\lib\site-packages\pip_internal\index.py", line 15, in
from pip._vendor import html5lib, requests, six ImportError: cannot import name requests
I'm on OS X 10.10.4 with Macports and Anaconda (condo 3.15.1).
During the process of building the robotic simulator ARGoS,
https://github.com/ilpincy/argos3
we ran into runtime 'qt' issues running the ARGoS examples.
[FATAL] Can't load library "/usr/local/lib/argos3/libargos3plugin_simulator_epuck.dylib" even after trying to add extensions for shared library (dylib) and module library (so):
/usr/local/lib/argos3/libargos3plugin_simulator_epuck.dylib: dlopen(/usr/local/lib/argos3/libargos3plugin_simulator_epuck.dylib, 1): Library not loaded: #rpath/./libQtOpenGL.4.dylib
I learned that cmake found 'qt' within Anaconda which had runtime problems.
-- Found Qt4: /Users/davidlaxer/anaconda/bin/qmake (found version "4.8.6")
Next, I installed qt4-mac:
sudo port install qt4-mac
---> Computing dependencies for qt4-mac
---> Fetching archive for qt4-mac
---> Attempting to fetch qt4-mac-4.8.7_0.darwin_14.x86_64.tbz2 from http://packages.macports.org/qt4-mac
---> Attempting to fetch qt4-mac-4.8.7_0.darwin_14.x86_64.tbz2.rmd160 from http://packages.macports.org/qt4-mac
---> Installing qt4-mac #4.8.7_0
---> Activating qt4-mac #4.8.7_0
NOTE: Qt database plugins for mysql55, postgresql91, and sqlite2 are NOT installed by this port; they are installed by qt4-mac-*-plugin instead.
---> Cleaning qt4-mac
---> Updating database of binaries
---> Scanning binaries for linking errors
---> No broken files found.
When I installed 'qt' with Macports, ipython qtconsole broke.
David-Laxers-MacBook-Pro:build_simulator davidlaxer$ ipython qtconsole
Traceback (most recent call last):
File "/Users/davidlaxer/anaconda/bin/ipython", line 6, in <module>
sys.exit(start_ipython())
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 573, in launch_instance
app.initialize(argv)
File "<string>", line 2, in initialize
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 321, in initialize
super(TerminalIPythonApp, self).initialize(argv)
File "<string>", line 2, in initialize
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/core/application.py", line 369, in initialize
self.parse_command_line(argv)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/terminal/ipapp.py", line 316, in parse_command_line
return super(TerminalIPythonApp, self).parse_command_line(argv)
File "<string>", line 2, in parse_command_line
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 471, in parse_command_line
return self.initialize_subcommand(subc, subargv)
File "<string>", line 2, in initialize_subcommand
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 75, in catch_config_error
return method(app, *args, **kwargs)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/config/application.py", line 402, in initialize_subcommand
subapp = import_item(subapp)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/utils/importstring.py", line 42, in import_item
module = __import__(package, fromlist=[obj])
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/qt/console/qtconsoleapp.py", line 50, in <module>
from IPython.external.qt import QtCore, QtGui
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/external/qt.py", line 23, in <module>
QtCore, QtGui, QtSvg, QT_API = load_qt(api_opts)
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/external/qt_loaders.py", line 277, in load_qt
result = loaders[api]()
File "/Users/davidlaxer/anaconda/lib/python2.7/site-packages/IPython/external/qt_loaders.py", line 184, in import_pyqt4
from PyQt4 import QtGui, QtCore, QtSvg
ImportError: dlopen(/Users/davidlaxer/anaconda/lib/python2.7/site-packages/PyQt4/QtGui.so, 2): Symbol not found: _iconv
Referenced from: /Users/davidlaxer/anaconda/lib//libxml2.2.dylib
Expected in: /opt/local/lib//libiconv.2.dylib
How is this supposed to work?