Tag Archives: python

[Solved] Mujoco Error: Missing path to your environment variable.

Using mujoco to report an error: missing path to your environment variable

Question:

Recently, you want to use pycharm to run the server program in the local server environment. Follow https://www.jb51.net/article/195691.htm After step configuration, try running Import mujoco_Py , error reported:

Missing path to your environment variable.  
Current values LD_LIBRARY_PATH= 
Please add following line to .bashrc: 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/.mujoco/mujoco200/bin

But I’ve added environment variables to ~ /. Bashrc

Solution:

Finally, the error reporting is solved by manually adding environment variables for the current operating environment:

In the menu bar -> Run -> Edit Configurations -> Add the corresponding environment variables to environment variables

Name Value
LD_ LIBRARY_ PATH $LD_ LIBRARY_ PATH:/root/.mujoco/mujoco200/bin

 

Gunicorn timeout error: [1] [critical] worker timeout [How to Solve]

1. Problem description

In a web project built with gunicorn + flash, because the machine learning model is used, the model needs to be loaded when requesting the interface for the first time. The model is loaded quickly when running locally, so it runs normally. The application is deployed to the server using docker (the model is mounted to the container through volume), The first request to load the model takes a long time, and the following errors are reported:

[2021-09-11 07:22:33 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:12)
[2021-09-11 07:22:35 +0000] [12] [INFO] Worker exiting (pid: 12)

Gunicorn ‘green Unicorn’ is a python WSGI HTTP server for UNIX. It is a pre forked worker model transplanted from Ruby’s Unicorn project. Gunicorn server is widely compatible with various web frameworks, with simple implementation, less use of server resources and quite fast speed.

2. Cause analysis

It can be seen from the error message that gunicorn’s worker process timed out, causing the process to exit and restart
refer to the official document of gunicorn and the description shown in the figure below:

3. Solution

From the documentation on the official website, we can know that the default timeout of gunicorn is 30s. If it exceeds 30s, the worker process will be killed and restarted.

Therefore, to solve this problem, you only need to set a large timeout: gunicorn to set the timeout

gunicorn -w 2 -b 0.0.0.0:4343  manage:app --timeout 120 

Add: -- timeout 120 to gunicorn’s startup command, indicating that the timeout is set to 120 seconds. Configure the timeout in the gunicorn. Conf.py configuration file of gunicorn

workers = 4  # Define the number of processes to be opened for processing requests at the same time, adjusted appropriately according to site traffic
worker_class = "gevent" # Use the gevent library to support asynchronous processing of requests and improve throughput
bind = "0.0.0.0:8500" # Listen to IP relaxation to facilitate communication between Dockers and between Dockers and hosts
timeout = 120 # Set the timeout to 120 seconds

For more configuration of the gunicorn. Conf.py file, see the official website

[Solved] Pycharm Use pip Error: Script file ‘D:\Anaconda3\envs\pytorch\Scripts\pip-script.py‘ is not present

Problem Description:

error reporting 1: error reporting for PIP installation: script file’d:\anaconda3\envs \ pytorch\scripts\PIP script. Py ‘is not present.
error reporting 2: PIP upgrade failed: script file’d:\anaconda3\envs\pytorch\scripts\PIP script. Py’ is not present.
as shown in the following figure:


Solution:

Baidu has had the following solutions for a long time:

# Method 1: Use the command line to go to the Anconda3\Scripts\ directory and execute the command, or if it is a virtual environment, go to the \Scripts\ directory under the virtual environment

    easy_install pip # I tried this method, but it didn't work for me 
    
# Method 2: Also go to the directory and execute the following statement

    python -m ensurepip --default-pip # Perfect solution

Django framework uses error reporting exception type: templatedoesnotexist

1、 Error: templatedoesnotexist

Exception Type: TemplateDoesNotExist

 

2、 Problem analysis and solution

Problem analysis: the accessed HTML file was not found

reason:

Django directly regards the template path as an absolute path, and the HTML file cannot be found.

After viewing the project setting file, you can see the setting method of template, including an option of “dirs”,
 

Solution:

'DIRS': [os.path.join(BASE_DIR), 'templates'],

Error in PIP install BS4 under Linux

1. The error information is as follows:

$ sudo pip install bs4==0.0.1
Collecting bs4==0.0.1
  Downloading http://pip.pgw.getui.com/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz
Collecting beautifulsoup4 (from bs4==0.0.1)
  Downloading http://pip.pgw.getui.com/packages/a1/69/daeee6d8f22c997e522cdbeb59641c4d31ab120aba0f2c799500f7456b7e/beautifulsoup4-4.10.0.tar.gz (399kB)
    100% |████████████████████████████████| 409kB 11.7MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-USqeae/beautifulsoup4/setup.py", line 7, in <module>
        from bs4 import __version__
      File "bs4/__init__.py", line 36, in <module>
        raise ImportError('You are trying to use a Python 3-specific version of Beautiful Soup under Python 2. This will not work. The final version of Beautiful Soup to support Python 2 was 4.9.3.')
    ImportError: You are trying to use a Python 3-specific version of Beautiful Soup under Python 2. This will not work. The final version of Beautiful Soup to support Python 2 was 4.9.3.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-USqeae/beautifulsoup4/

2 solution

Install beatifulsoup4 first

$ sudo  pip install beautifulsoup4==4.9.0
Collecting beautifulsoup4==4.9.0
  Downloading http://pip.pgw.getui.com/packages/2d/3e/8b2fc5d3c31c84d7209313f4059858f502f2e4a9d986693eca03fe325565/beautifulsoup4-4.9.0-py2-none-any.whl (109kB)
    100% |████████████████████████████████| 112kB 872kB/s
Collecting soupsieve<2.0 (from beautifulsoup4==4.9.0)
  Downloading http://pip.pgw.getui.com/packages/39/36/f35056eb9978a622bbcedc554993d10777e3c6ff1ca24cde53f4be9c5fc4/soupsieve-1.9.6-py2.py3-none-any.whl
Collecting backports.functools-lru-cache; python_version < "3" (from soupsieve<2.0->beautifulsoup4==4.9.0)
  Downloading http://pip.pgw.getui.com/packages/e5/c1/1a48a4bb9b515480d6c666977eeca9243be9fa9e6fb5a34be0ad9627f737/backports.functools_lru_cache-1.6.4-py2.py3-none-any.whl
Installing collected packages: backports.functools-lru-cache, soupsieve, beautifulsoup4
Successfully installed backports.functools-lru-cache-1.6.4 beautifulsoup4-4.9.0 soupsieve-1.9.6

Installing BS4

$ sudo  pip install  bs4==0.0.1
Collecting bs4==0.0.1
  Downloading http://pip.pgw.getui.com/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gz
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /usr/lib/python2.7/site-packages (from bs4==0.0.1)
Requirement already satisfied (use --upgrade to upgrade): soupsieve<2.0 in /usr/lib/python2.7/site-packages (from beautifulsoup4->bs4==0.0.1)
Requirement already satisfied (use --upgrade to upgrade): backports.functools-lru-cache; python_version < "3" in /usr/lib/python2.7/site-packages (from soupsieve<2.0->beautifulsoup4->bs4==0.0.1)
Installing collected packages: bs4
  Running setup.py install for bs4 ... done
Successfully installed bs4-0.0.1

Zlib.error: error – 3 while decompressing: incorrect header check in Python

As shown in the following code:

b64_encoded_bytes = base64.b64encode(zlib.compress(b'abcde'))
encoded_bytes_representation = str(b64_encoded_bytes)  # this the cause
zlib.decompress(base64.b64decode(encoded_bytes_representation))

Zlib.decopress error

zlib.error: Error -3 while decompressing: incorrect header check

The reason for this is the use of the str() method
The description of the str() method in the python3 documentation.
If neither encoding nor errors is given, str(object) returns object.str(), which is the “informal” or nicely printable string representation of object. For string objects, this is the string itself. If object does not have a str() method, then str() falls back to returning repr(object).
The str() method only serves to put the

b'eJxLTEpOSQUABcgB8A=='

Converted to

"b'eJxLTEpOSQUABcgB8A=='"

The correct conversion should be to

"eJxLTEpOSQUABcgB8A=="

The solution is to specify the encoding method in the str() method

str(b64_encoded_bytes, 'utf-8')

[Solved] Python Error: tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.

environment

Environment: docker
System: Ubuntu 18.04
graphics card: RTX 1080ti
tf-v: 1.15.0

Run the neural network model and report the error of the title

The screenshot of the error is as follows:

solution:

Add the following code after the import of the entry file:

config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.6  # 0.6 sometimes works better for folks
keras.backend.tensorflow_backend.set_session(tf.compat.v1.Session(config=config))

Limit the running memory of Tensorflow

[Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘

Original code:

def loadTxt(filenameTxt):
    txtList = [line.strip().decode('utf-8') for line in open(filenameTxt,'r').readlines()]#变成 unicode
    return txtList#unicode

report errors:

AttributeError: ‘str‘ object has no attribute ‘decode‘

Solution: decode the byte string

def loadTxt(filenameTxt):
    txtList = [line.strip().encode('utf-8').decode('utf-8') for line in open(filenameTxt,'r').readlines()]#变成 unicode
    return txtList#unicode

AttributeError: module ‘enum‘ has no attribute ‘IntFlag‘ [How to Solve]

The error details are as follows:

Traceback (most recent call last):
  File "/usr/local/bin/evo_traj", line 5, in <module>
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
    if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Original exception was:
Traceback (most recent call last):
  File "/usr/local/bin/evo_traj", line 5, in <module>
    import re
  File "/usr/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Problem analysis
this problem has not occurred before. It is suspected that the python iteration version conflict is caused by the update of Ubuntu system. It is recommended to turn off the automatic update of Ubuntu to prevent such problems. It takes a long time to solve some version conflict problems.

Solution:
the query found that pythonpath was set incorrectly. The configuration left by the previous use of python2 was saved in. Bashrc, resulting in python3 unable to find the correct enum location. After commenting out the relevant statements in bashrc, clear the $pythonpath variable:

 unset PYTHONPATH
 echo $PYTHONPATH

Then it can be used normally. Pythonpath is a multi-purpose configuration in python2. It is generally no longer needed after using python3.

Python quote error: * * * keyerror: u ‘\ uxx’ [How to Solve]

Problem: urllib.quote (xxx) error after running * * * keyerror: u '\ uxx'
reason: look at XXX type: & lt; type 'unicode'>, and params in urlib.quote (params) is a string. You can only guess that the encoding of the string does not meet the requirements, so the code XXX
solution: urlib.quote (XXX. Encode ("UTF-8") or urlib.quote (STR (xxx))

Examples are as follows:

>>> import urllib
>>> xxx = u'[{"test":"Test"}]'
>>> urllib.quote(xxx)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1298, in quote
    return ''.join(map(quoter, s))
KeyError: u'\u6d4b'
>>> type(xxx)
<type 'unicode'>
>>> urllib.quote(xxx.encode("utf-8"))
'%5B%7B%22test%22%3A%22%E6%B5%8B%E8%AF%95%22%7D%5D'
>>> urllib.quote(str(xxx))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)
>>> import sys
>>> sys.setdefaultencoding('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setdefaultencoding'
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding('utf-8')
>>> urllib.quote(str(xxx))
'%5B%7B%22test%22%3A%22%E6%B5%8B%E8%AF%95%22%7D%5D'