Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6184

docker-python error : ModuleNotFoundError: No module named '_distutils_hack'

$
0
0

i'm running a python/django app using docker and apache2 and it was working great ,, but suddnle when I try to run again am getting this error :

  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 ignoredError 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'

Here is an example of used files in the project :

Dockerfile

FROM ubuntuRUN apt-get update# Avoid tzdata infinite waiting bugARG DEBIAN_FRONTEND=noninteractiveENV TZ=Africa/CairoRUN apt cleanRUN apt-get updateRUN apt-get install -y apt-utils vim curl apache2 apache2-utils gitRUN apt -y install software-properties-commonRUN apt updateRUN add-apt-repository ppa:deadsnakes/ppaRUN apt -y install python3.10-full# Optional: Set Python 3.9 as the default Python versionRUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1# RUN apt-get -y install python3 libapache2-mod-wsgi-py3RUN apt-get -y install libapache2-mod-wsgi-py3RUN apt -y install certbot python3-certbot-apacheRUN apt-get -y install python3-pipRUN apt update# Check Python and pip versionsRUN python3 --version && \    pip3 --version#Add sf to avoid ln: failed to create hard link '/usr/bin/pip': File existsRUN ln -sf /usr/bin/pip3 /usr/bin/pipRUN pip install --upgrade pip --break-system-packagesRUN pip install django ptvsd --break-system-packagesRUN apt install wait-for-itRUN pip install cffi --upgrade --break-system-packagesRUN pip install -U pip setuptools --break-system-packagesRUN apt-get -y install gettextRUN apt-get -y install poppler-utilsRUN apt-get -y install redis-serverRUN apt-get install python3-pymysqlRUN a2enmod headersRUN service apache2 restartCOPY www/demo_app/water_maps/requirements.txt requirements.txtRUN python3 -m pip install --upgrade setuptoolsRUN pip install -r requirements.txt --break-system-packagesADD ./demo_site.conf /etc/apache2/sites-available/000-default.confEXPOSE 80 5432WORKDIR /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.pyWSGIPassAuthorization 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>

Viewing all articles
Browse latest Browse all 6184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>