How to fix ModuleNotFoundError: No module named 'encodings' to deploy Django Project

Viewed 113

I am trying to deploy a django project but currently facing an error that I am not sure the reason of it and I can not fix it.

I am using Linode Apache/2.4.46 (Ubuntu) Server. I managed to get the project work on 8000 port but everytime I try to get Apache server it shows the Apache/2.4.46 (Ubuntu) Server at ServerNo Port 80

I am desperatly trying to find a solution. I deleted the server and started from scratch twice and still it is not working

Here is thesudo tail -100 /var/log/apache2/error.log:

Python path configuration:
  PYTHONHOME = '/home/ahesham/Portfolio/venv'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python3'
  sys.base_prefix = '/home/ahesham/Portfolio/venv'
  sys.base_exec_prefix = '/home/ahesham/Portfolio/venv'
  sys.platlibdir = 'lib'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/ahesham/Portfolio/venv'
  sys.exec_prefix = '/home/ahesham/Portfolio/venv'
  sys.path = [
    '/home/ahesham/Portfolio/venv/lib/python39.zip',
    '/home/ahesham/Portfolio/venv/lib/python3.9',
    '/home/ahesham/Portfolio/venv/lib/python3.9/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Here is the cd /etc/apache2/sites-available/ ls-la:

total 36
drwxr-x---  5 ahesham ahesham  4096 Aug  7 15:30 .
drwxr-xr-x  3 root    root     4096 Aug  7 14:55 ..
-rw-------  1 ahesham ahesham    96 Aug  7 15:12 .bash_history
-rw-r--r--  1 ahesham ahesham   220 Aug  7 14:55 .bash_logout
-rw-r--r--  1 ahesham ahesham  3771 Aug  7 14:55 .bashrc
drwx------  3 ahesham ahesham  4096 Aug  7 16:16 .cache
drwxr-xr-x 10 ahesham www-data 4096 Aug  7 16:30 Portfolio
-rw-r--r--  1 ahesham ahesham   807 Aug  7 14:55 .profile
drwx------  2 ahesham ahesham  4096 Aug  7 15:09 .ssh
-rw-r--r--  1 ahesham ahesham     0 Aug  7 15:11 .sudo_as_admin_successful

Here is the sudo nano Portfolio.conf:

<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

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ServerName
        <Directory /var/www/html/>
             AllowOverride All
        </Directory>


        # 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

        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


        Alias /static /home/ahesham/Portfolio/static
        <Directory /home/ahesham/Portfolio/static>
                Require all granted
        </Directory>

        Alias /media /home/ahesham/Portfolio/media
        <Directory /home/ahesham/Portfolio/media>
                Require all granted
        </Directory>

        <Directory /home/ahesham/Portfolio/Portfolio>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

        WSGIScriptAlias / /home/ahesham/Portfolio/Portfolio/wsgi.py
        WSGIDaemonProcess Portfolio python-path=/home/ahesham/Portfolio python-home=/home/ahesham/Portfolio/venv
        WSGIProcessGroup Portfolio

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Here is the /etc/apache2/apache2.conf:

<Directory />
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

I have search and applied all the answers I have found but still can't fix it

0 Answers
Related