Tag Archives: python

The fastest way to solve the problem of error reporting from crypto.cipher import AES

In my personal development process, I need to use the encryption method, but in the process of quoting from crypto.cipher import AES, it has been reported that the crypto module does not exist. Baidu finally found a solution after a few days

 

I use Python 3.9

1、 First perform the following 2 steps

1.pip   install crypto

2.pip   install pycryptohome

2、 After the installation is completed, you can use it directly or prompt that it cannot be found:

1. Change crypto to uppercase

 

So far, the problem has been solved

 

Ubuntu Reportno moulde named tkinter

In the Ubuntu system, an error is reported by using Python Tkinter:
no mount named Tkinter
the following error appears after changing the code file to Tkinter

using sudo apt to install Python TK
in fact, a solution has been prompted in the error report, so you should read the tips carefully

GPY installation error: ERROR: Could not find a version that satisfies the requirement scipy…

The following error occurs when installing GPY with PIP

ERROR: Could not find a version that satisfies the requirement scipy<1.5.0,>=1.3.0 (from GPy) (from versions: 0.8.0, 0.9.0, 0.10.0, 0.10.1, 0.11.0, 0.12.0, 0.12.1, 0.13.0, 0.13.1, 0.13.2, 0.13.3, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.16.0, 0.16.1, 0.17.0, 0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 1.0.0b1, 1.0.0rc1, 1.0.0rc2, 1.0.0, 1.0.1, 1.1.0rc1, 1.1.0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.2.2, 1.2.3)
ERROR: No matching distribution found for scipy<1.5.0,>=1.3.0 (from GPy)

Solution: use PIP3

pip3 install GPy

[Solved] Error Mixed spaces and tabs no-mixed-spaces-and-tabs

"extensions": "eslint: Recommended" the attribute in the configuration file enables this rule.

Most code conventions require tabs or spaces for indentation. Therefore, if a single line code is indented with tabs and spaces, an error usually occurs.

This rule does not allow indenting with mixed spaces and tabs.

Example of error code for this rule:

/*eslint no-mixed-spaces-and-tabs: "error"*/

function add(x, y) {
// --->..return x + y;

      return x + y;
}

function main() {
// --->var x = 5,
// --->....y = 7;

    var x = 5,
        y = 7;
}

Example of the correct code for this rule:

/*eslint no-mixed-spaces-and-tabs: "error"*/

function add(x, y) {
// --->return x + y;
    return x + y;
}

This rule has a string option.

"smart tabs" when the latter is used for alignment, it is allowed to mix space and labels.

Smart tag

The correct code example for this rule includes the following "smart tabs" Options:

/*eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/

function main() {
// --->var x = 5,
// --->....y = 7;

    var x = 5,
        y = 7;
}

Add this line:

/*eslint no-mixed-spaces-and-tabs: [“error”, “smart-tabs”]*/


<template>
	<comp-setup>
		
	</comp-setup>
</template>

<script>
/*eslint no-mixed-spaces-and-tabs: ["error", "smart-tabs"]*/
import CompSetup from './components/setupview'
export default {
  name: 'App',
  components: {
	  CompSetup,
  }
}
</script>

<style>

</style>

Robotframework post error“:“Internal Server Error“,“message“:“syntax error, expect

In the post request,
‘content type’: ‘application/JSON; Charset = UTF-8 ‘
data = ${data} is used to transfer parameters, resulting in an error

Error “:” internal server error “,” message “:” syntax error, expect

Solution:
After changing data=data to json{data}, the execution succeeds
PS: in the post request, data parameters need to be transferred according to the content type

NameError: name “defaultParams“ is not defined [How to Solve]

When the source code Matplotlib has the following parameters for setting Chinese or negative numbers, a NameError will appear in pyinstaller packaging: name ‘defaultparams’ is not defined error

plt.rcParams['font.sans-serif'] = ['STSong']  
plt.rcParams['axes.unicode_minus'] = False  

Solution:

Reduce Matplotlib to version 3.2.2

conda install matplotlib==3.2.2

Note: pyinstaller 3.6 version    Python 3.6.13 version

OSError libespeak.so.1 error: no such file or directory [How to Solve]

Traceback (most recent call last):
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/__init__.py”, line 20, in init
eng = _activeEngines[driverName]
File “/usr/lib/python3.8/weakref.py”, line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “mqttToTts.py”, line 23, in <module>
tts = Tts()
File “mqttToTts.py”, line 7, in __init__
self.engine = pyttsx3.init()
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/__init__.py”, line 22, in init
eng = Engine(driverName, debug)
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/engine.py”, line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/driver.py”, line 50, in __init__
self._module = importlib.import_module(name)
File “/usr/lib/python3.8/importlib/__init__.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “<frozen importlib._bootstrap>”, line 1014, in _gcd_import
File “<frozen importlib._bootstrap>”, line 991, in _find_and_load
File “<frozen importlib._bootstrap>”, line 975, in _find_and_load_unlocked
File “<frozen importlib._bootstrap>”, line 671, in _load_unlocked
File “<frozen importlib._bootstrap_external>”, line 783, in exec_module
File “<frozen importlib._bootstrap>”, line 219, in _call_with_frames_removed
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py”, line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File “/home/summergao/.local/lib/python3.8/site-packages/pyttsx3/drivers/_espeak.py”, line 18, in <module>
dll = cdll.LoadLibrary(‘libespeak.so.1’)
File “/usr/lib/python3.8/ctypes/__init__.py”, line 451, in LoadLibrary
return self._dlltype(name)
File “/usr/lib/python3.8/ctypes/__init__.py”, line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory

When using python3 to do text-to-speech, I installed pyttsx3 and ran the program with the above error
The reason is that before installing pyttsx3, I need to install a speech environment: “espeak”
Installation command:

sudo apt-get update && sudo apt-get install espeak

Python Error: SyntaxError: ‘break‘ outside loop

report errors:

SyntaxError: 'break' outside loop

Break can only be used in a while loop or a for loop. If it is used in an if conditional statement, an error will be reported: syntax error: ‘break’ outside loop. However, if the if conditional statement is nested inside a while loop or a for loop,
if you do not pay attention to the format when corresponding to while, an error will also be reported

[Solved] AttributeError: OperationJson instance has no attribute ‘data‘

Wrong:
#coding:utf-8
import json
class OperetionJson:

	def __init__(self,file_path=None):
		if file_path == None:
			self.file_path = '../dataconfig/user.json'
		else:
			self.file_path = file_path
		    self.data = self.read_data();
		    

Right:
```python
#coding:utf-8
import json
class OperetionJson:

	def __init__(self,file_path=None):
		if file_path == None:
			self.file_path = '../dataconfig/user.json'
		else:
			self.file_path = file_path
		self.data = self.read_data()
	

Ionic Save to Gallery Plugin IOS Error: Method ‘requestAuthorization:’ not defined in Plugin ‘PhotoLibrary’ ERROR: Method ‘xxx’ not defined

Error in IOS when ionic is saved to the gallery plug-in error: method ‘requestauthorization:’ not defined in plugin ‘photolibrary’ error: method ‘xxx’ not defined in plugin

In IOS, when saving pictures to mobile photo album, the error is as follows

ERROR: Method 'requestAuthorization:' not defined in Plugin 'PhotoLibrary'

FAILED pluginJSON = ["PhotoLibrary815393554","PhotoLibrary","requestAuthorization",[{"write":true,"read":true}]]

resolvent

cordova plugin rm cordova-plugin-photo-library
cordova plugin add https://github.com/nilebma/cordova-plugin-photo-library.git

Due to GitHub network problems, you can use the following command

npm install --save @ionic-native/photo-library
cordova plugin add https://gitee.com/liuzhuo8081/cordova-plugin-photo-library.git