Collect all kinds of python programming exceptions and fault solutions.

How to save email messge item generated using exchangelib library in python

I have used exchangelib library to download emails from my Inbox.
The messages are eventually instance of exchangelib.items.Message.
I want to save this entire email as .msg file so that I can later

ConversionError: Failed to convert value(s) to axis units

I have a dataframe dd containing 84 rows and 3 columns.
Now I want to plot an Area Plot with it, and use its index as xticks, so I do the following:
But I got this

CNN on python with Keras

I made a simple CNN that classifies dogs and cats and I want this CNN to detect images that aren't cats or dogs and this must be a third different class. How to implement this? should I use R-CNN or

Is there a function to add WOE, calculated on Training data, to the whole data set? (python)

I am working on some python code to predict Default rate of loans handed out by a bank.
I have calculated the WOE and information value (IV) on the training set
(using the following code: https://

Why doesn't [[]] == list(list())

I just randomly observed the following in Python and am curious to know the reason why this evaluates to False:
list(list()) == [[]]
Interestingly if you rearrange the syntax in the following ways...

Python and Powershell issue even after adding it to path

When I try to run a python command in Powershell, I get this error
Program 'python' failed to run: No application is associated with the specified file for this
I have python installed in C:\Use...

"Can't find starting number (in the name of file)" when trying to read frames from hevc (h265) video in opencv

I'm trying to read frames from a hevc(h265) .avi video in opencv-python (python3, latest version) but keeps throwing
OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\videoio\src\cap_image...

Discord py bot not triggering on_member_join function

My discord py bot wont trigger the "on_member_join" event. Everything else works fine. I have other event methods that trigger normally. What am i doing wrong here? It doesnt even print the console

Understanding the Python `id` Function Across Interpreters

I have noticed that when calling the id function in Python, that some values have a consistent value across all interpreter instances. I understand that Python keeps integers under 256 in memory, b...

How can I dismiss some classes when creating dataset in pytorch?

It is my first experience with PyTorch. I cloned the repository to google colab. There are some classes (image folders) in the repository that I want to dismiss (let's say folder cat). How can I ac...

Why class method must have self parameter in python?

class Student:
def __init__(self, name): = name
I know why self is used in this code. This can take different students and make differnt attributes
student1 = Student()

sqlalchemy.exc.InvalidRequestError: Could not reflect: requested table(s) not available in Engine

I am trying to push the excel xlsx data to mySQl Alchemy by using this simple code...
import pandas as pd
import os
import sqlalchemy
mydir = (os.getcwd()).replace('\\', '/') + '/'
# MySQL Conne...

How to run UVICORN in Heroku?

So I have figured out how to code a fastAPI and I am ready to deploy my script to heroku that I have worked with fastAPI ( however the problem is that when I do a requ...

Django Unit test is giving Anonymous user while login

I've the below code for Django login Unit test.
"""This is the unit test case for form element"""
from django.test import TestCase
from django.contrib.auth.models import User
class TestForm(TestC...

pyTelegramBotAPI disable link preview

Currently writing my first bot using pyTelegramBotAPI. I want to disable link previews on certain messages. How do I do this?

ValueError: images do not match when blending pictures in PIL

I have been messing around in python to see if I could "mix" two pictures together. What I mean by that is so that the image is transparent and you can see two pictures together. If that still does...

error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:715: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

I am trying to save a part of an image inside a bounding box as follow:
digit = thresh[x:x+w,y:y+h]
But I got following error.
error: OpenCV(4.1.2) /io/opencv/mo...

Pycharm warning: Class 'Iterable' does not define '__getitem__'

I have recently been learning python and I was trying out some things in Pycharm when I noticed the following warning caused by this piece of code:
Class 'Iterable' does not define '__getitem__'...

Can't install Pandas in PyCharm

I'm a total newbie with programming. To get startet a little I've tried to install Pandas in PyCharm with pip install Pandas. When I try to install it via the Terminal or the Settings I receive the

Removing SEP token in Bert for text classification

Given a sentiment classification dataset, I want to fine-tune Bert.
As you know that BERT created to predict the next sentence given the current sentence. Thus, to make the network aware of this, ...

Log embed thinks it's empty (on_message_edit)

To start with, I'm trying to make my bot log message editing. Basically that code works and logs messages that were edited, but it causes some problems in the terminal:

raise ValueError("Cannot convert {0!r} to Excel".format(value))

I am trying to use the df.dropna function and I want to nest it multiple times using and by the sign ',' and or by using the sign '|' according to the docs

How to install Tensorflow with Python3.8

Whenever I try to install tensorflow with pip on python3.8 I get that tensorflow is not found. I have realized later on that it is not supported with python3.8, but I don't know how to make it run.

Opencv-Python error on when installing PyForms

When I try to install PyForms by 'pip install pyforms', it threw an error:

How to get the current worksheet gid?

I use Python and Gspread to create a gsheet with about 40 worksheet containing datas about accounts.
On the first worksheet, I want to put something like a summary with a link to the account's work...

Issue in installing AWS EB CLI

I'm following this instruction to install eb cli, but it raise this error:
Will not install to the user site because it will lack sys.path precedence to python-dateutil in c:\virtual envs\python_X...

How to make this loop succesful after a succesful attempt?

The retry function tries to execute an operation that might fail, it retries the operation for a number of attempts. Currently the code will keep executing the function even if it succeeds. Modify ...

adding two Values in two kivy screens and getting the result

I'm trying to build an app that can calculate the sum of two values. I have a screen called Therdwindow that has three text input widgets.
from import App
from import App
from ...

How may i do equalized learning rate with tensorflow 2?

I am trying to implement StyleGAN with tensorflow version 2, and i have no ideas how to do equalized learning rate.
I tried to scale gradients with this way:
But it doesn't works correctly.
Pls help.

Django.admin - How to make a Modelfield disable if other field is == False

I'm new to Django, and I'm developing a website in which I need to automate the creation of new pages through Django admin platform. So the idea is to create a new tab on the main menu of the site ...

Using Python Pandas df.loc to locate a partially variable value

I'm trying to use the df.loc from pandas to locate a partially variable value in my dataframe.
in my dataframe there are times and dates combined
for example
Time Col1 Col2

Very fast rolling hash in Python?

I'm writing a toy rsync-like tool in Python. Like many similar tools, it will first use a very fast hash as the rolling hash, and then a SHA256 once a match has been found (but the latter is out of...

How do I include a built-in django widget template in my custom widget template?

I am writing a Django widget in my app. However, as the widget is an extension of a <textarea> I would like to include within it the Django Textarea widget: django/forms/templates/django/forms/

Can I retrain OpenCV DNN face detector using my own face dataset and .pb .pbtxt files provided by OpenCV?

I want to fine tune existing OpenCV DNN face detector to a face images database that I own. I have opencv_face_detector.pbtxt and opencv_face_detector_uint8.pb tensorflow files provided by OpenCV. I

How to show exactly 4 numbers after decimal point without rounding in Python?

I want to calculate square root of numbers and print them with exactly 4 numbers after decimal point without rounding.
This code rounds the numbers
num="%.4f" % num
and this one doesn't show 1.0...

Python - How to send message with Viber bot?

I want to create some sort of Viber bot to send messages to Viber user, actually just to notify them.
I've tried to follow their documentation, but I couldn't make it work, because it was not clea...

Is it true that in multiprocessing, each process gets it's own GIL in CPython? How different is that from creating new runtimes?

Are there any caveats to it? I have a few questions related to it.
How costly is it to create more GILs? Is it any different from creating a separate python runtime? Once a new GIL is created, wil...

How to check if string contains chars which are not in a list?

I have a question. How do I check if a python string contains chars which are not in a given list?
Here is the list (set):

Unable to start Anaconda Navigator in Windows 10

Stackoverflow community, I installed Anaconda on my PC but I am unable to launch the Anaconda Navigator.
I have already read some previous questions about this type of problem, and I even reinstall...

How to post nested arrays in Django REST Framework with Postman form-data?

I have a nested writable serializer with array fields. I need to test it with form-data because one of the field type is ImageField. When I changed the ImageField into CharField it worked fine if I

scikit multilearn: accuracy_score ValueError: multiclass-multioutput is not supported

I want to predict samples that can be in more than 1 label at a time (multi label classification). So I use the scikit-multilearn library and have successfully fitted a classifier, and can even pre...

jupyter server : not started, no kernel in vs code

i am trying to use jupyter notebooks from vs code and installed jupyter notebook extension and i am using (base)conda environment for execution.
while this happened
Error: Jupyter cannot be started.

Koalas is incompatible with Sklearn - ValueError: could not convert string to float: 'x'

I try to adapt to Koalas the code that runs well with Pandas:
import pandas as pd
from databricks import koalas as ks
from sklearn import preprocessing
pdf = pd.DataFrame({'x':range(3), 'y':[1,2,...

Python Durable Rules post json function and date formatting not working

Posting Json for durable rules does not allow to format date.
Posting string into variable works.
from datetime import datetime
start = datetime.strptime(a, "%d-%m-%Y")
end = dat...

How to modify model and weight values after post-quantization in tf-lite

import logging
import tensorflow.compat.v2 as tf
except Exception:
from tensorflow import keras

Pytorch ImageNet dataset

I am unable to download the original ImageNet dataset from their official website. However, I found out that pytorch has ImageNet as one of it’s torch vision datasets.
Q1. Is that the original Ima...

Pytorch Autograd gives different gradients when using .clamp instead of torch.relu

I'm still working on my understanding of the PyTorch autograd system. One thing I'm struggling at is to understand why .clamp(min=0) and nn.functional.relu() seem to have different backward passes....

OpenCV (Python) face detection program not terminating

I have been writing a face detection program in python using OpenCV. It is working fine, but the program is not terminating after closing the window in which faces are detected.
I have tried cv2.

Disable all Kivy elements in loop, enable certain elements

Im trying to disable all GUI widgets except a few:
for i_d in self.ids: #Disables all GUI elements
#if [i_d] != 'lblConnection' or [i_d] != 'swCOM' or [i_d] != 'swSYS' or [i_d] != 'btnTestConn...

Parsing KML file using pyKML

I'm learning how to parse KML files in Python using the pyKML module. The specific file I'm using can be found here and I've also added it at the bottom of this post. I have saved the file on my co...