Category Archives: Python

Error in Python data fetching “[SSL: Certificate]_ VERIFY_ FAILED] certificate verify failed (_ The solution of “None” problem in SSL. C: 841

 

Python:Python 3.6.6(Python Downloads)

Refer to the online solution, is the problem caused by the self signed certificate. The simple solution is to cancel the certificate verification, that is, to add:

ssl._create_default_https_context = ssl._create_unverified_context

How to Solve Error: [Errno 11001] getaddrinfo failed

When starting Django project, we encountered: error: [errno 11001] getaddrinfo failed error

You can run the following command in Ubuntu, but if you transfer the project to windows 10, there will be an error:

# --insecure argument to force django to process static files, when closing debug is added (--insecute)
python manage.py  runserver 0:8000 --insecure
# or
python manage.py  runserver 0:8000

Debug code in settings.py file

DEBUG = False
ALLOWED_HOSTS = ["*"]

Run the following command in Windows 10 to solve the problem

python manage.py runserver 0.0.0.0:8000 --insecute
# or
python manage.py runserver 0.0.0.0:8000

Python pandas.read_ Oserror: initializing from file failed

Python version: Python 3.6
version pandas.read_ Oserror: initializing from file failed is usually caused by two cases: one is that the function parameter is path instead of file name, the other is that the function parameter is in Chinese.

# -*- coding: utf-8 -*-
"""
Created on Mon Jun  4 09:44:36 2018
@author: wfxu
"""
import pandas as pd
da1=pd.read_csv('F:\\datas')
da2=pd.read_csv('F:\\2.0 datas\\lists.csv')

In both cases, the error message is the same:

Traceback (most recent call last):
	(Error reporting details are not shown)
  File "pandas/_libs/parsers.pyx", line 720, in pandas._libs.parsers.TextReader._setup_parser_source

OSError: Initializing from file failed

For the first case, it’s very simple. The reason is that you don’t put the file name after the path. Just add the file name after the path. You can also switch the folder to the folder where the target file is located in the code. The process is too complicated, I don’t like it or recommend it, so I won’t show it
in the second case, even if the path and file name are complete, an error is still reported because there is Chinese in this parameter, but doesn’t Python 3 already support Chinese?Referring to the cause of the error and the source code of panda, it is found that the read of panda is called_ When using the CSV () method, C engine is used as the parser engine by default. When the file name contains Chinese, using C engine will make mistakes in some cases. So I’m calling read_ The problem can be solved by specifying engine as Python when using the CSV () method.

da4=pd.read_csv('F:\\datas\\lists.csv',engine='python')

For the second case, another solution is to use the open function to open the file, and then access the data in it

da3=pd.read_csv(open('F:\\4.0 \\2.0 datas\\02.lists.csv'))

Well, the reasons for this error are understood, and the solution is very simple and crude, isn’t it very simple!

This application failed to start because no Qt platform plugin could be initialized

I also encountered this error when I started after installing the Mumu simulator. Today, I also encountered this problem when debugging the pycarm breakpoint. When I ran to the breakpoint, this error box would pop up:

(at this time, I had a hunch that this was a very big problem (FOG))
neither Baidu nor Google solved my problem, I did it again through pip, but it didn’t work. Later, I solved this problem by deleting environment variables directly

this is Qt5 automatically installed in anconda. It should be the wrong version. Maybe the one installed with PIP later was right, but the one in the environment variable was not right. After deleting it directly, I didn’t add any additional environment variables, so the problem was solved directly

import win32api; Importerror: DLL load failed: the specified program was not found

Error information

(venv) D:\pyvenv_xlwings64\venv>pip list
Package    Version
---------- -------
comtypes   1.1.7
pip        19.2.3
PyQt5      5.13.1
PyQt5-sip  4.19.19
pywin32    225
setuptools 41.2.0
wheel      0.33.6
xlwings    0.15.3

(venv) D:\pyvenv_xlwings64\venv>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\pyvenv_xlwings64\venv\lib\site-packages\xlwings\__init__.py", line 42, in <module>
    from . import _xlwindows as xlplatform
  File "D:\pyvenv_xlwings64\venv\lib\site-packages\xlwings\_xlwindows.py", line 10, in <module>
    import win32api
ImportError: DLL load failed: the specified program was not found.
>>>

Cause of the problem

There is a problem with the new version 224 and 225. Just go back to version 223

(venv) D:\pyvenv_xlwings64\venv>pip install pywin32==223
Collecting pywin32==223
  Downloading https://files.pythonhosted.org/packages/9f/9d/f4b2170e8ff5d825cd4398856fee88f6c70c60bce0aa8411ed17c1e1b21f/pywin32-223-cp36-cp36m-win_amd64.whl (9.0MB)
     |████████████████████████████████| 9.0MB 218kB/s
Installing collected packages: pywin32
Successfully installed pywin32-223

(venv) D:\pyvenv_xlwings64\venv>
(venv) D:\pyvenv_xlwings64\venv>
(venv) D:\pyvenv_xlwings64\venv>
(venv) D:\pyvenv_xlwings64\venv>pip list
Package    Version
---------- -------
comtypes   1.1.7
pip        19.2.3
PyQt5      5.13.1
PyQt5-sip  4.19.19
pywin32    223
setuptools 41.2.0
wheel      0.33.6
xlwings    0.15.3

(venv) D:\pyvenv_xlwings64\venv>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwings
>>> 

Python Error: “failed to execute pyi_rth_pkgres”

reference resources: https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages

First, uninstall pyinstaller, then download and install it from GitHub

pip uninstall pyinstaller
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

Bloggers solve the problem through the above methods

Weighted cross entropy loss function: tf.nn.weighted_cross_entropy_with_logits

tf.nn.weighted_cross_entropy_with_logits Function

tf.nn.weighted_cross_entropy_with_logits(
  targets,
  logits,
  pos_weight,
  name=None
)

Defined in: tensorflow/Python/OPS/NN_ impl.py 。

The weighted cross entropy was calculated.

0 Similar to sigmoid?Cross?Entropy?With?Logits () , except POS?U weight It allows people to weigh recall rate and accuracy by weighting up or down the cost of positive error relative to negative error.

0 Generally, the cross entropy cost is defined as:

targets * -log(sigmoid(logits)) +
  (1 - targets) * -log(1 - sigmoid(logits))

Value POS?U weights &> 1 The false negative count is reduced and the recall rate is increased. Instead, set POS?U weights & lt; 1 It can reduce false positive count and improve accuracy. You can see from the following It is introduced as the multiplication coefficient of the positive target term in the loss expression

targets * -log(sigmoid(logits)) * pos_weight +
  (1 - targets) * -log(1 - sigmoid(logits))

For simplicity, let x = Logits, z = targets, q = POS?U weight . The losses are:

 qz * -log(sigmoid(x)) + (1 - z) * -log(1 - sigmoid(x))
= qz * -log(1/(1 + exp(-x))) + (1 - z) * -log(exp(-x)/(1 + exp(-x)))
= qz * log(1 + exp(-x)) + (1 - z) * (-log(exp(-x)) + log(1 + exp(-x)))
= qz * log(1 + exp(-x)) + (1 - z) * (x + log(1 + exp(-x))
= (1 - z) * x + (qz + 1 - z) * log(1 + exp(-x))
= (1 - z) * x + (1 + (q - 1) * z) * log(1 + exp(-x))

Set L = (1 + (Q – 1) * z) to ensure stability and avoid overflow

(1 - z) * x + l * (log(1 + exp(-abs(x))) + max(-x, 0))

Logits and targets must have the same type and shape.

Parameters:

Targets: a tensor with the same type and shape as Logits.

Logits: a tensor of type float32 or float64.

pos_ Weight: the coefficient used in the positive sample.

Name: the name of the operation (optional).

Return:

Tensors with the same shape as Logits with component weighted logic loss.

Possible exceptions:

Valueerror: if Logits and targets do not have the same shape.

How to solve syntax error in Python: unexpected EOF while parsing

This is my code

salary = input("Please enter your salary at: ")
things = [["iphone","5000"],["mac pro","12000"],["coffee","31"],["book","81"],["bike","800"]]
while True :

Error type is

File “C:/Users/googol/PycharmProjects/untitled/ shopping.py “, line 5

^
SyntaxError: unexpected EOF while parsing
Process finished with exit code 1

Solution: because the code I wrote constitutes an infinite loop, so the error, the solution is to add the end condition