Category Archives: Python

[Solved] python MATLAB Error: OSError: MATLAB Engine for Python supports Python version 2.7, 3.4, 3.5 and3.6, but your version of python is 3.8

Because the coordinates of broken line graph and curve graph are to be read recently, Python is used to call matlab to try, but an error is reported in this process:

The matlab2017b I use does not support Python 3 Version 8.

Solution:

I chose to create a virtual environment in anaconda.

As follows:

Because the maximum version of 3.6 is supported, a version of 3.6 is created

Open pycharm, set it in setting, and select Add

Generally, the virtual environment created is in the envs of anaconda

After setting the environment, it can be executed successfully again

Test:

Run successfully

[Solved] django DRF This field may not be null, This field cannot be blank

target

You need to change the original mandatory field to non mandatory

realization

First, update the fields in models, and add null = true, default = none, blank = true

1
2
name = CharField(max_length=64, verbose_name='name', null=True, default=None, blank=True)
account = CharField(max_length=64, verbose_name='account', null=True, default=None, blank=True)

serializers update

1
2
name = CharField(required=False)
account = CharField(required=False)

execute python manage.py makemigrations
execute python manage.py migrate

Error:

May appear this error:

1
This field may not be null.

or

1
This field cannot be blank.

Solution:

You need to change serializers to this

1
2
name = CharField(required=False, allow_blank=True, allow_null=True)
account = CharField(required=False, allow_blank=True, allow_null=True)

allow_blank=True to solve This field cannot be blank.
allow_null=True to solve This field may not be null.

[Solved] 64-bit Python calls 32-bit Oracle client error: Cx_Oracle.DatabaseError: DPI-1047

problem

The operating system is 64 bit Python and 32 bit Oracle client. For other reasons, the Oracle client cannot be changed to 64 bit, resulting in Cx_Oracle64 bit cannot be used, CX_Oracle32 bit cannot be installed.

reason

Under Windows environment, if 64 bit Python is installed, CX_Oracle is used, the 64 bit Oracle client is called by default. In this case, we can only install Cx_Oracle win_Amd 64-bit version.

Solution:

1. First install CX_Oracle matching the current Python version, my is Python 3.8. The installed version is: Cx_Oracle-8.3.0-cp38-cp38-win_amd64.whl

2. Download the relevant Oracle instantclient (instant client) and unzip it to a folder convenient for calling

Download address: https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html

The version I downloaded is: instantclient-basiclite-windows-x64-19.13.0.0.0dbru.Zip, you can try several times, there is always one for you

3. Unzip the instantclient and change the environment variable in the Python code to adjust the Oracle driver location.

My unzipped address is:

E:\software\Python\instantclient-basiclite-windows.x64-19.13.0.0.0dbru

The code adjustment method is

import os

os.environ[‘path’] =  r’E:\software\Python\instantclient-basiclite-windows.x64-19.13.0.0.0dbru\instantclient_19_13′

import cx_Oracle

Now CX_Oracle can call normally

[Solved] python Connect Oracle Error: DPI-1047

Prompt when Python connects to Oracle:: databaseerror: dpi-1047: cannot locate a 64 bit Oracle Client Library: “the specified module could not be found” See https://oracle.github.io/odpi/doc/installation.html#windows for help

Enter according to the error prompt https://oracle.github.io/odpi/doc/installation.html#windows, download the corresponding instant client package, then unzip the configuration environment variables and run it again. Generally, it can run successfully to solve the problem.

If dpi-104 error is still prompted, you need to check whether VC + + is installed. The check method is to run genezi.com under the downloaded instant client directory Exe program. For example: C:\Oracle\instantclient_21_3\genezi.exe. If there is an error during execution, it means VC_redist is not installed correctly. reenter https://oracle.github.io/odpi/doc/installation.html#windows Page, download the corresponding VC according to the corresponding Oracle version_redist.exe version.

Download and install to solve the problem.

[Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa6 in position 9737: ill

Django2. 2 after installation, use runserver for development. When an error occurs, the error message is only displayed on the console command line, and only one line is displayed on the front page

“A server error occurred. Please contact the administrator.”
troubleshooting is very inconvenient. Check the error information on the console carefully and give a prompt

Unicode decodeerror: ‘GBK’ codec can’t decode byte 0xa6 in position 9737: ill…
it is judged that this version of Django cannot be displayed normally due to the code reading problem of the error message code
follow the prompts to find the python installation path\lib\site_packages\Django\views\debug.Py, after it is opened, the modification is about 332 lines, which will:

    with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:

Change to

    with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:

That is, set the encoding, and then restart runserver. The error information can be displayed on the page normally.

[Solved] Error: jedi-vim failed to initialize Python: jedi-vim requires Vim with support for Python 2 or 3

This plug-in is installed in GVIM

Error: jedi-vim failed to initialize Python: Jedi-vim requires Vim with support for Python 2 or 3 · Issue #1018 · davidhalter/jedi-vim (github.com)

But when you open a python file, you will be prompted with a bunch of red words, mainly because Python is not supported

There is a reply in the author:

You can enter whether Python print (‘sb ‘) or: Python 3 print (‘sb’) can run in VIM, but not input: version

Check the version of GVIM. Download the 64-bit version GVIM

The version of GVIM is now 64 bit

Check whether Python is 64-bit or not in CMD

After keeping the versions of GVIM and python 64-bit, it still doesn’t work on the command line. Opening a py file is a pile of red prompts

So add such a line of code to _vimrc to specify the path of python3

Then on the command line, type: Python 3 print (‘sb ‘)

Output normal

Reopen a py file and enter After that, I found that the prompts were normal, and there were no previous prompts

After tossing me for a day, I am irritable, by the way, I have to install a plug-in>pip install jedi

Python OSError: [errno 22] invalid argument: [How to Solve]

When executing the report on the web page to generate a word document, the following two errors occur:

1.ValueError: Invalid format string error 
2.Python OSError: [Errno 22] Invalid argument:report name xxxx

Through the query, it is found that these two problems are caused by this sentence:

file_name = 'REPORTS_%s.docx'%time.strftime('%Y-%m-%d %H:%M:%s') 
open with(file_name,'rb')as fp:
  ...

Solution to 1: if you want to change the small s in% s to the large s, you won’t report an error.

Solution to2: there is a problem in time acquisition. Colons cannot be used between hours, minutes and seconds!!!, Just separate them with an underline. Amend to read:

file_name = 'REPORTS_%s.docx'%time.strftime('%Y-%m-%d %H_%M_%S')

As for the solution of problem 2, I checked the relevant information and found that the following special characters [?*: “& lt; & gt;/|] cannot appear in the file name under windows. When using open with to read and write a file, the file name cannot be

Contains the above keywords. It can be solved by changing to other characters.

No error will be reported after the above problems are solved

[Solved] NodeNotFoundError(self.error_message, self.key, origin=self.origin) django.db.migrations.excep

Error code:

raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration jobs.0001_initial dependencies reference nonexistent parent node ('auth', '0012_alter_user_first_name_max_length')

Solution:

The first step is to uninstall Django, PIP uninstall Django
the second step is to delete the remaining Django folder in the/lib/site packages package
the third step is to delete all pycache folders in the project, delete files under migrations, and retain init py.
Step 3: reinstall the corresponding version of Django, otherwise some will be incompatible.
Step 4: execute the migration. Success

[Solved] pip/pytest Error: Fatal error in launcher: Unable to create process using

After moving the python directory, execute the EXE program under Python \ scripts. The prompt is as follows

Fatal error in launcher: Unable to create process using ‘”e:\myidle\python3\python.exe” “F:\MyIDLE\Python3\Scripts\pytest.exe” ‘: ???????????
the reason is that after modifying the directory, the directory path in exe has not changed. Use notpad + + to open the EXE file, pull it to the bottom, and modify the path to the moved Python directory