Django 给出 AttributeError - '_thread._local' 对象没有属性 'state'
Django gives AttributeError - '_thread._local' object has no attribute 'state'
我正在创建一个 django 应用程序,它需要使用 sympy python 包进行数学计算。
为了举例说明所涉及的计算类型,让我们考虑一下我们有三个等式-
- x+y=100
- y=200
- z+x=300
我使用 sympy 包的 solve() 方法计算了 x、y 和 z 的所有可能值。然而,这给出了一个 AttributeError - '_thread._local' object has no attribute 'state'
下面是完整的追溯-
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/results/24/
Django Version: 3.0.3
Python Version: 3.6.10
Installed Applications:
['hlasoftware.apps.HlasoftwareConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Anjali Jain\HLA\hlasoftware\views.py", line 163, in results
reactive_eplets=predict.mfi_predictions(data,cutoff2) #Predict MFI of eplets
File "C:\Users\Anjali Jain\HLA\hlasoftware\Predict_mfi.py", line 282, in mfi_predictions
sol=solve_eq(list_of_eq,ep)
File "C:\Users\Anjali Jain\HLA\hlasoftware\Predict_mfi.py", line 133, in solve_eq
sol=solve((list_of_eq),(list_of_var))
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 1096, in solve
solution = _solve_system(f, symbols, **flags)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 1763, in _solve_system
result = solve_linear_system(matrix, *symbols, **flags)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 2237, in solve_linear_system
inv = inv_quick(system[:, :-1])
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 2568, in inv_quick
return M.inv()
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 2252, in inv
try_block_diag=try_block_diag)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\inverse.py", line 459, in _inv
rv = M.inverse_GE(iszerofunc=iszerofunc)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 2236, in inverse_GE
return _inv_GE(self, iszerofunc=iszerofunc)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\inverse.py", line 242, in _inv_GE
red = big.rref(iszerofunc=iszerofunc, simplify=True)[0]
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 164, in rref
pivots=pivots, normalize_last=normalize_last)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 306, in _rref
normalize_last, normalize=True, zero_above=True)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 129, in _row_reduce
normalize=normalize, zero_above=zero_above)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 60, in _row_reduce_list
isimp = _get_intermediate_simp(_dotprodsimp)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\utilities.py", line 34, in _get_intermediate_simp
if dotprodsimp is False or _dotprodsimp_state.state is False:
Exception Type: AttributeError at /results/24/
Exception Value: '_thread._local' object has no attribute 'state'
我尝试了以下技巧,但都给出了相同的错误-
- 正在重新安装 sympy 包
- 使用 python manage.py --runserver --nothreading
- 使用 python manage.py --runserver --nothreading --noreload
任何关于如何解决此错误的 suggestion/feedback 将不胜感激。请帮帮我!
这是 sympy 1.6.1 中的一个错误,虽然尚未发布修复程序,但已修复:
https://github.com/sympy/sympy/issues/19809
您可以使用 sympy 1.6.0 或 git 的最新 sympy master 或手动应用修复。
我正在创建一个 django 应用程序,它需要使用 sympy python 包进行数学计算。
为了举例说明所涉及的计算类型,让我们考虑一下我们有三个等式-
- x+y=100
- y=200
- z+x=300
我使用 sympy 包的 solve() 方法计算了 x、y 和 z 的所有可能值。然而,这给出了一个 AttributeError - '_thread._local' object has no attribute 'state'
下面是完整的追溯-
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/results/24/
Django Version: 3.0.3
Python Version: 3.6.10
Installed Applications:
['hlasoftware.apps.HlasoftwareConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'storages']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Anjali Jain\HLA\hlasoftware\views.py", line 163, in results
reactive_eplets=predict.mfi_predictions(data,cutoff2) #Predict MFI of eplets
File "C:\Users\Anjali Jain\HLA\hlasoftware\Predict_mfi.py", line 282, in mfi_predictions
sol=solve_eq(list_of_eq,ep)
File "C:\Users\Anjali Jain\HLA\hlasoftware\Predict_mfi.py", line 133, in solve_eq
sol=solve((list_of_eq),(list_of_var))
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 1096, in solve
solution = _solve_system(f, symbols, **flags)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 1763, in _solve_system
result = solve_linear_system(matrix, *symbols, **flags)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 2237, in solve_linear_system
inv = inv_quick(system[:, :-1])
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\solvers\solvers.py", line 2568, in inv_quick
return M.inv()
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 2252, in inv
try_block_diag=try_block_diag)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\inverse.py", line 459, in _inv
rv = M.inverse_GE(iszerofunc=iszerofunc)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 2236, in inverse_GE
return _inv_GE(self, iszerofunc=iszerofunc)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\inverse.py", line 242, in _inv_GE
red = big.rref(iszerofunc=iszerofunc, simplify=True)[0]
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\matrices.py", line 164, in rref
pivots=pivots, normalize_last=normalize_last)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 306, in _rref
normalize_last, normalize=True, zero_above=True)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 129, in _row_reduce
normalize=normalize, zero_above=zero_above)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\reductions.py", line 60, in _row_reduce_list
isimp = _get_intermediate_simp(_dotprodsimp)
File "C:\Users\Anjali Jain\anaconda3\envs\hlaenv\lib\site-packages\sympy\matrices\utilities.py", line 34, in _get_intermediate_simp
if dotprodsimp is False or _dotprodsimp_state.state is False:
Exception Type: AttributeError at /results/24/
Exception Value: '_thread._local' object has no attribute 'state'
我尝试了以下技巧,但都给出了相同的错误-
- 正在重新安装 sympy 包
- 使用 python manage.py --runserver --nothreading
- 使用 python manage.py --runserver --nothreading --noreload
任何关于如何解决此错误的 suggestion/feedback 将不胜感激。请帮帮我!
这是 sympy 1.6.1 中的一个错误,虽然尚未发布修复程序,但已修复: https://github.com/sympy/sympy/issues/19809
您可以使用 sympy 1.6.0 或 git 的最新 sympy master 或手动应用修复。