Category Archives: How to Fix

When calling time module – time / datetime in wxPython, an error is reported. Valueerror: unknown locale: zh cn

1. Key words: valueerror: unknown locale: zh cn

A lot of instructions on the Internet are about the language environment. Set up a round down, or not.

2. Key words: wxPython valueerror: unknown locale: zh cn

We found the following link through the wall:

https://github.com/pyinstaller/pyinstaller/issues/4874

The corresponding relationship of the version number mentioned below

 
  PyInstaller==3.4 wxPython==4.0.4 good

  PyInstaller==3.6 wxPython==4.0.4 good

  PyInstaller==3.6 wxPython==4.0.7 good

  PyInstaller==3.6 wxPython==4.0.7.post2 good

  PyInstaller==3.6 wxPython==4.1.0 bad

 
3. Upgrade or reduce the version number of wxpathon. Then upgrade the version.

pip3 install upgrade wxPython

NettyAvroRpcClient RPC connection error

2014-12-19 01:05:42,141 (lifecycleSupervisor-1-1) [WARN – org.apache.flume.sink.AbstractRpcSink.start(AbstractRpcSink. java:294 )] Unable to create Rpc client using hostname: xxx.xxx.xxx.xxx, port: 41100
org.apache.flume.FlumeException: NettyAvroRpcClient { host: 121.41.49.51, port: 41100 }: RPC connection error

This problem occurs when flume uses Avro to accept data.

First, let’s see if the port of the connected server is monitored

If you want to send data to port 4383 of 192.168.1.1, you need a server listening to this window, otherwise RPC connection failure will occur

ERROR: Invalid HADOOP_COMMON_HOME

Error when starting Hadoop and yarn
/start yarn. Sh
error: invalid Hadoop_ COMMON_ HOME

Solution:
1. Check Java first_ Is home configured correctly

java
javac

2. Then check whether Hadoop home is configured correctly

hadoop version
Hadoop 3.1.3
Source code repository https://gitbox.apache.org/repos/asf/hadoop.git -r ba631c436b806728f8ec2f54ab1e289526c90579
Compiled by ztang on 2019-09-12T02:47Z
Compiled with protoc 2.5.0
From source with checksum ec785077c385118ac91aadde5ec9799
This command was run using /opt/module/hadoop-3.1.3/share/hadoop/common/hadoop-common-3.1.3.jar

When generating a test report in HTML format, report [typeerror: a bytes like object is required, not ‘STR’]

1、 Error information

E:\pythonProject\study\venv\Scripts\python.exe E:/pythonProject/case/test_ login.py
…Traceback (most recent call last):
  File “E:\pythonProject\case\test_ login.py”, line 71, in < module>
    runner.run(suit)  # Call the run() method under the htmltestrunner class to run the use case suite
class   File “E:\pythonProject\study\venv\lib\site-packages\HTMLTestRunner\HTMLTestRunner.py”, line 631, in run
    self.generateReport(test, result)
  File “E:\pythonProject\study\venv\lib\site-packages\HTMLTestRunner\HTMLTestRunner.py”, line 691, in generateReport
    self.stream.write(output)
TypeError: a bytes-like object is required, not ‘str’

2、 Source code

#Path and name of test report

dir = “E:/pythonProject/login_ report.html”

#”WB” creates or opens a binary file and writes the finished data

filename = open(dir, “wb”)

#Call htmltestrunner class to define test report content

runner = HTMLTestRunner.HTMLTestRunner(stream=filename, title=”Testcase Report”, description=”testcases”)

runner.run(suit)     #  Call the run () method under the htmltestrunner class to run the use case suite

filename.close()    #  Close test report file

3、 Solutions

#Path and name of test report

dir = “E:/pythonProject/login_ report.html”

#”W” creates or opens a new file and writes the finished data

filename = open(dir, “w”)

#Call htmltestrunner class to define test report content

runner = HTMLTestRunner.HTMLTestRunner(stream=filename, title=”Testcase Report”, description=”testcases”)

runner.run(suit)     #  Call the run () method under the htmltestrunner class to run the use case suite

filename.close()    #  Close test report file

ModuleNotFoundError: No module named xxx

Background: I encapsulate a package and contain multiple sub packages. Each sub package has multiple different moodles. When I refer to moodles again, it is OK to run in pychar. However, when I put this folder in Linux, there is an error: modulenotfounderror: no module named ‘package’  。
The structure is as follows:

package:

    ├─ sub_package0

        │ ├─ __init__.py

        │ ├─ utils.py

        │ └─ www.py

    ├─ sub_package1

        │ ├─ __init__.py

        │ ├─ utils1.py

        │ └─ www1.py

    ....

    ├─ __init__.py

    ├─ abc.py

    └─ xyz.py

After online Baidu, mainly tried two methods:

(1) One is to add environment variable pythonpath in. Bashrc of Linux environment http://blog.sina.com.cn/s/blog_ 9b1b494a0102vrl3.html

(2) In each moudule, add a path through the sys module https://www.cnblogs.com/dreamyu/p/7889959.html

After trying the first method, we found that the above error was still reported, while the second method was too cumbersome because it had to be added to each module. In order to save trouble, put the package directly into anaconda3’s installation path anaconda3/lib/python3.6/site-packages, and the problem is solved. The site packages library is actually the storage location of the package and module installed by PIP install.

 
Supplementary knowledge

Module: module. A. Py file can be called a module. Using module can avoid the conflict between function name and variable name. Functions and variables with the same name can be stored in different modules, but it should also be noted that the names of built-in functions should not conflict with each other.

Package: package. Different modules are organized by directory, similar to folder. Modules are organized by package to avoid conflicts. After the package is introduced, as long as the top-level package name does not conflict with others, all modules will not conflict with others. Please note that there is a under each package directory__ init__. Py file, this file must exist, otherwise, python will regard this directory as a normal directory instead of a package__ init__. Py can be an empty file or have Python code, because can be an empty file__ init__. Py itself is a module, and its module name is its package name.

 

Python failed to use PIL writer library. TTF, etc. oserror: cannot open resource

Error information

Read the error information,
return freetype (font),
return freetype font (font, size, index, encoding, layout)_ Oserror: cannot open resource
generally, an error is reported. The reason is that there is a problem in using the resource file
failure reason:
1. First of all, check whether the path you bind is correct. Some people directly bind to the font file in the path of C: (Windows) fonts. This is OK, but you need to use it in Python/
2. If you bind to the font file in the path of C: (Windows) fonts, you can’t use it. Reason: the name of the font may be too long. At this time, we can rename it, Then re install to the path, or directly put your own bound path
3. The bound path is correct, but still an error is reported. Trust the font library to C:// Windows/fonts to see if it is installed. If it is not installed, it may not work

File "./ClothStore/captcha/captcha.py", line 123, in <listcomp>
    for size in font_sizes or (65, 70, 75)])
  File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 655, in truetype
    return freetype(font)
  File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 652, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/ClothStore/venv/lib/python3.7/site-packages/PIL/ImageFont.py", line 194, in __init__
    font, size, index, encoding, layout_engine=layout_engine
OSError: cannot open resource