[英]Certain python libraries are not loading in my Django application in production, but load fine in local server
In my views.py file of my Django application I'm trying to load the 'transformers' library with the following command:在我的 Django 应用程序的 views.py 文件中,我尝试使用以下命令加载“变形金刚”库:
from transformers import pipeline
This works in my local environment, but on my Linux server at Linode, when I try to load my website, the page tries to load for 5 minutes then I get a Timeout error.这适用于我的本地环境,但在我位于 Linode 的 Linux 服务器上,当我尝试加载我的网站时,该页面尝试加载 5 分钟,然后出现超时错误。 I don't understand what is going on, I know I have installed the library correctly.
我不明白发生了什么,我知道我已经正确安装了库。 I have also run the same code in the python shell on my server and it loads fine, it's is just that if I load it in my Django views.py file, no page of my website loads.
我还在我的服务器上的 python shell 中运行了相同的代码并且它加载正常,只是如果我将它加载到我的 Django views.py 文件中,我的网站没有页面加载。
My server: Ubuntu 20.04 LTS, Nanode 1GB: 1 CPU, 25GB Storage, 1GB RAM我的服务器:Ubuntu 20.04 LTS,Nanode 1GB:1 个 CPU,25GB 存储空间,1GB RAM
Library: transformers==3.0.2图书馆:变形金刚==3.0.2
I also have the same problem when I try to load tensorflow. All the other libraries are loading fine, like pytorch and pandas etc. I've been trying to solve this problem since more than a week, I've also changed hosts from GCP to Linode, but it's still the same.当我尝试加载 tensorflow 时,我也遇到了同样的问题。所有其他库都加载正常,如 pytorch 和 pandas 等。一个多星期以来我一直在尝试解决这个问题,我还从 GCP 更改了主机到 Linode,但它仍然是一样的。
Edit: I created a new server and installed everything from scratch and used a virtualenv this time, but still its the same problem.编辑:我创建了一个新服务器并从头开始安装了所有东西,这次使用了 virtualenv,但仍然是同样的问题。 Following are the installed libraries outputted from
pip freeze
:以下是
pip freeze
输出的已安装库:
asgiref==3.2.10
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
Django==3.0.7
djangorestframework==3.11.0
filelock==3.0.12
future==0.18.2
idna==2.10
joblib==0.16.0
numpy==1.19.1
packaging==20.4
Pillow==7.2.0
pyparsing==2.4.7
pytz==2020.1
regex==2020.7.14
requests==2.24.0
sacremoses==0.0.43
sentencepiece==0.1.91
six==1.15.0
sqlparse==0.3.1
tokenizers==0.8.1rc1
torch==1.5.1+cpu
torchvision==0.6.1+cpu
tqdm==4.48.0
transformers==3.0.2
urllib3==1.25.10
I also know transformers library is installed because if I try to import some library that doesn't exist then I simply get an error, like I should.我也知道安装了 transformers 库,因为如果我尝试导入一些不存在的库,那么我只会得到一个错误,就像我应该的那样。 But in this case it just loads forever and doesn't output any error.
但在这种情况下,它只是永远加载并且不会 output 任何错误。 This is so bizarre.
这太奇怪了。
Maybe you just have to create or update your requirements.txt file.也许您只需要创建或更新您的requirements.txt文件。
Here is the command: pip freeze > requirements.txt
这是命令:
pip freeze > requirements.txt
Some third party packages for Python which use C extension modules, and this includes scipy and numpy, will only work in the Python main interpreter and cannot be used in sub interpreters as mod_wsgi by default uses.
Python 的一些第三方包使用 C 扩展模块,包括 scipy 和 numpy,只能在 Python 主解释器中使用,不能在子解释器中使用,因为 mod_wsgi 默认使用。
transformers
library uses numpy, so you should force the WSGI application to run in the main interpreter of the process by changing apache config: transformers
库使用 numpy,因此您应该通过更改 apache 配置强制 WSGI 应用程序在进程的主解释器中运行:
## open apache config
$ nano /etc/apache2/sites-enabled/000-default.conf
## add this line to apache config
WSGIApplicationGroup %{GLOBAL}
## restart apache
$ systemctl restart apache2
now it works!!现在可以了!!
for more information visit the link above.欲了解更多信息,请访问上面的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.