docker-python 错误:ModuleNotFoundError:没有名为“_distutils_hack”的模块
122
0
我正在使用 docker 和 apache2 运行一个 python/django 应用程序,它运行得很好,但是当我尝试再次运行时突然出现此错误:Traceback(最近一次调用最后一次):文件 \'...
我正在使用 docker 和 apache2 运行一个 python/django 应用程序,它运行良好,但是当我尝试再次运行时突然出现此错误:
Traceback (most recent call last):
File "<frozen site>", line 201, in addpackage
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
Remainder of file ignored
Traceback (most recent call last):
File "<frozen site>", line 201, in addpackage
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
Remainder of file ignored
Error processing line 1 of /usr/lib/python3/dist-packages/distutils-precedence.pth:
Traceback (most recent call last):
File "<frozen site>", line 201, in addpackage
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_distutils_hack'
Remainder of file ignored
[Wed May 29 15:43:45.395312 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] mod_wsgi (pid=26): Failed to exec Python script file '/var/www/html/demo_app/water_maps/wsgi.py'.
[Wed May 29 15:43:45.395343 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] mod_wsgi (pid=26): Exception occurred processing WSGI script '/var/www/html/demo_app/water_maps/wsgi.py'.
[Wed May 29 15:43:45.395501 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] Traceback (most recent call last):
[Wed May 29 15:43:45.401671 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] File "/var/www/html/demo_app/water_maps/wsgi.py", line 12, in <module>
[Wed May 29 15:43:45.401687 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] from django.core.wsgi import get_wsgi_application
[Wed May 29 15:43:45.401704 2024] [wsgi:error] [pid 26:tid 132520276391616] [client 172.27.0.1:40422] ModuleNotFoundError: No module named 'django'
以下是项目中使用的文件的示例:
Dockerfile
FROM ubuntu
RUN apt-get update
# Avoid tzdata infinite waiting bug
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Africa/Cairo
RUN apt clean
RUN apt-get update
RUN apt-get install -y apt-utils vim curl apache2 apache2-utils git
RUN apt -y install software-properties-common
RUN apt update
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt -y install python3.10-full
# Optional: Set Python 3.9 as the default Python version
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# RUN apt-get -y install python3 libapache2-mod-wsgi-py3
RUN apt-get -y install libapache2-mod-wsgi-py3
RUN apt -y install certbot python3-certbot-apache
RUN apt-get -y install python3-pip
RUN apt update
# Check Python and pip versions
RUN python3 --version && \
pip3 --version
#Add sf to avoid ln: failed to create hard link '/usr/bin/pip': File exists
RUN ln -sf /usr/bin/pip3 /usr/bin/pip
RUN pip install --upgrade pip --break-system-packages
RUN pip install django ptvsd --break-system-packages
RUN apt install wait-for-it
RUN pip install cffi --upgrade --break-system-packages
RUN pip install -U pip setuptools --break-system-packages
RUN apt-get -y install gettext
RUN apt-get -y install poppler-utils
RUN apt-get -y install redis-server
RUN apt-get install python3-pymysql
RUN a2enmod headers
RUN service apache2 restart
COPY www/demo_app/water_maps/requirements.txt requirements.txt
RUN python3 -m pip install --upgrade setuptools
RUN pip install -r requirements.txt --break-system-packages
ADD ./demo_site.conf /etc/apache2/sites-available/000-default.conf
EXPOSE 80 5432
WORKDIR /var/www/html/demo_app
#CMD ["apache2ctl", "-D", "FOREGROUND"]
#CMD ["python", "manage.py", "migrate", "--no-input"]
docker-compose.yaml
version: "2"
services:
db:
image: postgres:14
restart: always
volumes:
- ./data/db:/var/lib/postgresql/data
- ./www/:/var/www/html
- ./www/demo_app/kml_files:/var/www/html/demo_app/kml_files
- ./www/demo_app/temp_kml_file:/var/www/html/demo_app/temp_kml_file
- ./www/demo_app/upload:/var/www/html/demo_app/upload
- ./data/log:/var/log/apache2
ports:
- '5432:5432'
environment:
- POSTGRES_DB=database_innvoentiq
- POSTGRES_USER=database_user_innvoentiq
- POSTGRES_PASSWORD=Yahoo000@
django-apache2:
build: .
container_name: water_maps
restart: always
environment:
- POSTGRES_DB=database_innvoentiq
- POSTGRES_USER=database_user_innvoentiq
- POSTGRES_PASSWORD=Yahoo000@
ports:
- 5000:80
- 5001:443
# - 80:80
# - 443:443
volumes:
- ./www/:/var/www/html
- ./www/demo_app/kml_files:/var/www/html/demo_app/kml_files
- ./www/demo_app/temp_kml_file:/var/www/html/demo_app/temp_kml_file
- ./www/demo_app/upload:/var/www/html/demo_app/upload
- ./data/log:/var/log/apache2
# - ./data/config/etc/apache2:/etc/apache2
# command: sh -c 'python3 manage.py migrate && python3 manage.py loaddata the_db.json '
command: sh -c 'wait-for-it db:5432 -- python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && python3 manage.py compilemessages && apache2ctl -D FOREGROUND'
# command: sh -c 'wait-for-it db:5432 -- python manage.py migrate && python manage.py loaddata last.json && apache2ctl -D FOREGROUND'
depends_on:
- db
/demo_site.conf
WSGIPythonPath /var/www/html/demo_app
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
# ServerName test3.watermaps-eg.com
# ServerAlias test3.watermaps-eg.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/
Alias /static /var/www/html/demo_app/static
Alias /en/upload /var/www/html/demo_app/upload
Alias /ar/upload /var/www/html/demo_app/upload
Alias /upload /var/www/html/demo_app/upload
WSGIScriptAlias / /var/www/html/demo_app/water_maps/wsgi.py
WSGIPassAuthorization On
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
<Directory /var/www/html/demo_app>
Require all granted
</Directory>
<Directory /var/www/html/demo_app/static>
Require all granted
</Directory>
<Directory /var/www/html/demo_app/upload>
Require all granted
</Directory>
<Directory /var/www/html/demo_app/water_maps>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Header add Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "*"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
TimeOut 7200
</VirtualHost>
收藏的用户(0)
X
正在加载信息~
-
引用 8楼
请参阅下面已修复的代码,上面的代码有几个问题:
- dgesv 的第二个参数必须等于一
- 缺少整数枢轴数组
- 右边的 b 被解决方案覆盖,因此您必须将初始 b 复制到 x 中。
#include "api_scilab.h" #include "Scierror.h" #include "BOOL.h" #include "localization.h" extern void dgesv_(int* n, int* nrhs, double* A, int* lda, int* ipiv, double* b, int* ldb, int* info); static const char fname[] = "foo6"; int sci_foo6(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt* opt, int nout, scilabVar* out) { int i = 0; int n = 0; // System dimension int iOne = 1; double* A = NULL; // Coefficient matrix double* b = NULL; // Right-hand side vector double* x = NULL; // Solution int* iPiv = NULL; int info = 0; /* Check the number of input and output arguments */ if (nin != 2 || nout != 1) { Scierror(77, _("%s: Wrong number of input or output arguments: 2 inputs and 1 output expected.\n"), fname); return 1; } /* Check the types of input arguments */ if (scilab_isDouble(env, in[0]) == 0 || scilab_isMatrix2d(env, in[0]) == 0 || scilab_isComplex(env, in[0]) == 1 || scilab_isDouble(env, in[1]) == 0 || scilab_isMatrix2d(env, in[1]) == 0 || scilab_isComplex(env, in[1]) == 1) { Scierror(999, _("%s: Wrong type for input arguments. Double matrices expected.\n"), fname); return 1; } /* Get the dimension of the coefficient matrix */ int rowA = 0, colA = 0, rowB = 0, colB = 0; scilab_getDim2d(env, in[0], &rowA, &colA); scilab_getDim2d(env, in[1], &rowB, &colB); if (rowA != colA || rowB != rowA || colB != 1) { Scierror(999, _("%s: Incorrect dimensions. Coefficient matrix should be square and vector should be a column vector of the same size.\n"), fname); return 1; } n = rowA; /* Get data from input arguments */ scilab_getDoubleArray(env, in[0], &A); scilab_getDoubleArray(env, in[1], &b); /* Solve the system of linear equations */ x = (double*)malloc(n * sizeof(double)); for (i = 0; i < n; i++) { x[i] = b[i]; } iPiv = (int*)malloc(n * sizeof(int)); dgesv_(&n, &iOne, A, &n, iPiv, x, &n, &info); if (info != 0) { Scierror(999, _("%s: LAPACK dgesv function failed with error code %d.\n"), fname, info); free(x); free(iPiv); return 1; } /* Create the output argument and copy the result */ out[0] = scilab_createDoubleMatrix2d(env, 1, n, 0); double* xPtr = NULL; scilab_getDoubleArray(env, out[0], &xPtr); for (i = 0; i < n; i++) { xPtr[i] = x[i]; } free(x); free(iPiv); return 0; }
没有给出编译和链接的说明(上面的源代码应该保存在
sci_foo6.c
):ilib_build('foo6',['foo6','sci_foo6','csci6'],"sci_foo6.c",[]); exec loader.sce
然后正确计算出解决方案:
--> A = [2, 1; -1, 2]; --> b = [1;2]; --> x = foo6(A,b) x = 0. 1.