Tag Archives: python

Pychar reported an error. Unable to set the python SDK in Python 3.8. This SDK appears to be invalid.

Problem Description:

After switching a new project, the installation of pyGame package fails and prompts that you cannot
install pyGame in Python 3.8 (py)_ xiaoxiaole) (E:\homestead\py_ Xiaoxiaole/venv/scripts/python. Exe) to set up the python SDK
this SDK appears to be invalid.




Solution:

py_ Xiaoxiaole this project has just been deleted. I don’t know why this interpreter is selected by default first set up the Python interpreter

Select all to display
select the above Python SDK. If it is not available, a new one can be added

when there is an available Python SDK

the pyGame package is successfully installed again and the invalid Python SDK is deleted.

Plt.acorr() Function Error: ValueError: object too deep for desired array

sketch

Note that the input data needs to be one-dimensional. Otherwise, it’s strange to report an error( Don’t ask me why I know)

Correct code:

import matplotlib.pyplot as plt
import numpy as np
data = np.random.random(100)
plt.acorr(data)
plt.show()

Error code:

import matplotlib.pyplot as plt
import numpy as np
data = np.random.random((1, 100))
plt.acorr(data)
plt.show()

[Solved] TypeError: not all arguments converted during string formatting

When formatting the output of a string, one of the methods is as follows:

for value in ['A', 'B', 'C']:
    print('output: %s' % value)

When I print the running status of the sub process, print() I found several strings in the list, but the error is as follows:

TypeError: not all arguments converted during string formatting

Not all the parameters are converted during the string formatting period. I looked at the location of the error. It turned out that % was wrongly typed, and it became $, and I didn’t know the reason at first. I saw this error for the first time and sent this information to everyone for reference. This is a low-level mistake

Supplement: several ways of string output

Direct print() output

print('str1', 'str2', 'str3', '...')

'%s' % value Placeholder output

# 1. Single
>>> name = 'Jason'
>>> print('name: %s' % name)
name: Jason
# 2.Multiple
>>> name1, name2 = 'Jason', 'Bob'
>>> print('name1: %s; name2: %s' % (name1, name2))
name1:, Jason; name2: Bob
# Output order can also be customized
>>> print('name1: %s; name2: %s' % (name2, name1))
name1: Bob; name2: Jason

When outputting multiple string variables, multiple variables after % need to be enclosed in parentheses, otherwise the error of insufficient parameters will be reported

TypeError: not enough arguments for format string

format() format output

# 1. Single
>>> '{}'.format('world')
'world'
# 2. Multiple
>>> word1, word2 = 'hello', 'world'
>>> hello_world = '{}, {}'.format(word1, word2)
>>> hello_world
'hello, world'
# Output order can also be customized
>>> hello_world = '{1}, {1}'.format(word1, word2)
>>> hello_world
'world, world'

When output at specified position, all {} must have subscripts of parameters, otherwise it will not be able to convert from manual field number to automatic field number valueerror error:

ValueError: cannot switch from manual field specification to automatic field numbering

It must also be within the subscript range, otherwise an overrun indexerror error will be reported

IndexError: Replacement index 2 out of range for positional args tuple

Python Import Error: SystemError: Parent module ‘‘ not loaded, cannot perform relative import

System error: parent module “not loaded, can not perform relative import when importing Python package

When using flash for web development, the structure of the project is reset as follows:
write the picture description here
when running the project again, the system error: parent module “not loaded, cannot perform relative import will appear. Through the error location, it is found that the problem is caused by the packet guidance.

from .app import create_ app

The “parent module” is not loaded and cannot be imported. Why is there such a problem
by viewing the project structure, use

from web_ flask.app import create_ app

At this time, there are more package guiding problems
write the picture description here
first locate yourself in views.py and delete the package guiding statement

from .models import Users

Then, use the local guide
from web_ Flash. App. Models import users
User = users (1 ‘sun’)
so far, the problem has been solved
or you can add the corresponding Python path with sys.path.append
to solve the problem———————

EnvironmentError:mysql config not found

MySQL for Python Library in Python is equivalent to the jdbc driver corresponding to MySQL in Java

1. Install MySQL first

sudo apt-get install mysql-server

 

2. Install MySQL Python

Download mysql-python-1.2.3.tar.gz (see the attachment) and unzip it to the specified directory.

Compile and configure MySQL Python in the decompressed mysql-python-1.2.3 directory

python setup.py build

At this time, the system reports an error: environmenterror: MySQL_ config not found

Obviously there is no mysql_ Configure this file

Execute find/- name MySQL_ Config, there is no data, indicating that there is no MySQL in the system_ Configure this file

 

 

Someone on the Internet explained that MySQL installed with apt get does not have mysql_ Config is the name of this file

Solution:

(1) Ubuntu next

Execute sudo apt get install libmysqld dev

(2) Fedora next

Execute sudo Yum install Python devel

If it appears: my_ Config. H: without that file or directory, execute: sudo Yum install MySQL devel

Note: Yum is also written in Python, and/usr/bin/Python is called by default. This is the python that comes with the system itself. You can install it in/usr/local/bin/python, so you’d better not uninstall the python that comes with the system. The python you download doesn’t have the yum module.

 

Execute at this time   find/-name mysql_ Config found this file under/usr/bin /

Then modify the site.cfg file in the mysql-python-1.2.3 directory

Remove MySQL_ Config = XXX and change to MySQL_ config=/usr/bin/mysql_ Config (in MySQL)_ The directory on the machine where the config file is located shall prevail.)

Execute the following command to compile and install successfully:

python setup.py build

python setup.py install

http://zhoujianghai.iteye.com/blog/1520666

Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3

Python 2 writes binary file randomly:

with open('/python2/random.bin','w') as f:
    f.write(os.urandom(10))

However, using Python 3 will report an error:

TypeError:must be str, not bytes

The reason is: Python 3 adds a new parameter named encoding to the open function, and the default value of this new parameter is “UTF-8”. In this way, when the read and write operations are carried out on the file handle, the system requires the developer to pass in the instance containing Unicode characters instead of the byte instance containing binary data.

resolvent:

Use binary write mode (“WB”) to open the file to be operated, instead of using character write mode (“W”) as before.

The method of adapting both Python 3 and python 2 is as follows

with open('python3/rndom.bin','wb') as f:
    f.write(os.urandom(10))

There is a similar problem when the file reads data. The solution to this problem is similar: open the file in ‘RB’ mode (binary mode) instead of ‘R’ mode.

Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3

Python 2 writes binary file randomly:

with open('/python2/random.bin','w') as f:
    f.write(os.urandom(10))

However, using Python 3 will report an error:

TypeError:must be str, not bytes

The reason is: Python 3 adds a new parameter named encoding to the open function, and the default value of this new parameter is “UTF-8”. In this way, when the read and write operations are carried out on the file handle, the system requires the developer to pass in the instance containing Unicode characters instead of the byte instance containing binary data.

resolvent:

Use binary write mode (“WB”) to open the file to be operated, instead of using character write mode (“W”) as before.

The method of adapting both Python 3 and python 2 is as follows

with open('python3/rndom.bin','wb') as f:
    f.write(os.urandom(10))

There is a similar problem when the file reads data. The solution to this problem is similar: open the file in ‘RB’ mode (binary mode) instead of ‘R’ mode.

Reproduced in: https://www.cnblogs.com/circleyuan/p/10350202.html

[Solved] ImportError: cannot import name ‘delayed‘ from ‘sklearn.utils.fixes‘

Problem Description:

Call imbalanced today_ An error is reported when the module is enabled:
importerror: cannot import name ‘delayed’ from ‘sklearn. Utils. Fixes’

Cause analysis:

Sklearn library, not updated in time. As a result, the sklearn.utils.fixes.py file does not have a delayed module.


Solution:

Update the sklearn library with the following command

conda update scikit-learn

AttributeError: ‘_io.TextIOWrapper‘ object has no attribute ‘softspace‘

Write the title of the table of contents here

1. Problem presentation 2. Solutions

1. Problem presentation

Problem display:

when I was learning the file module, I encountered such a situation. How can I solve this situation?

2. Solutions

This involves a version problem. As we all know, Python is mainly divided into Python 2 and python 3. When we check the python official website, we can see that
(Python website address: www.python. ORG)

it can be seen that in versions above 3.0, the softspace attribute may have been removed, so use the command line py – 2 (if you do not install python2, you need to install python2 first, python2 and python3 can be installed at the same time, and use py – 2 and py – 3 to switch under Windows Environment) to switch to python2.7, Open a file to view the softspace property, and the command line executes normally.