Category Archives: python-3.x

python 3.4 mod_wsgi error installing

I'm having a heck of a time trying to install mod_wsgi for apache 2.4 / python 3.4 right now. I've been looking at some other answers but don't seem to be helping. I set up a virtual environment and attempted:

pip install mod_wsgi

to start the process, but I keep getting an error:

Failed building wheel for mod-wsgi building 'mod_wsgi.server.mod_wsgi' extension error: Microsoft Visual C++ 10.0 is required. Get it with "Microsoft Windows SDK 7.1": www.microsoft.com/download/details.aspx?id=8279

Some people mentioned the easiest remedy is to install the visual studio community edition, but I already have Visual Studio 2017 installed. I also checked my installations and I have the Microsoft Visual C++ 2010 x64 and x86 Redistirbutables installed.

edit: I also attempted to go to the link that was provided and install the windows sdk, after which there was still no fix

Edit 2:

Path environment variables:

E:\platforms\python3.4.4\;
E:\platforms\python3.4.4\Scripts;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
E:\platforms\jdk8u172\bin;
C:\Program Files\Microsoft MPI\Bin\;
E:\platforms\python3.6.5\Scripts\;
E:\platforms\python3.6.5;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
E:\Git\cmd;
E:\Git\mingw64\bin;
E:\Git\usr\bin;
C:\Program Files\dotnet\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Program Files (x86)\GtkSharp\2.12\bin;
C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;
E:\TortoiseGit\bin;
%GROOVY_HOME%\bin;
%SYSTEMROOT%\System32\OpenSSH\;
E:\platforms\node10.1.0\;
E:\IDE\vs2017\VC\Auxiliary\Build;

python 3.4 mod_wsgi error installing

I'm having a heck of a time trying to install mod_wsgi for apache 2.4 / python 3.4 right now. I've been looking at some other answers but don't seem to be helping. I set up a virtual environment and attempted:

pip install mod_wsgi

to start the process, but I keep getting an error:

Failed building wheel for mod-wsgi building 'mod_wsgi.server.mod_wsgi' extension error: Microsoft Visual C++ 10.0 is required. Get it with "Microsoft Windows SDK 7.1": www.microsoft.com/download/details.aspx?id=8279

Some people mentioned the easiest remedy is to install the visual studio community edition, but I already have Visual Studio 2017 installed. I also checked my installations and I have the Microsoft Visual C++ 2010 x64 and x86 Redistirbutables installed.

edit: I also attempted to go to the link that was provided and install the windows sdk, after which there was still no fix

Edit 2:

Path environment variables:

E:\platforms\python3.4.4\;
E:\platforms\python3.4.4\Scripts;
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
E:\platforms\jdk8u172\bin;
C:\Program Files\Microsoft MPI\Bin\;
E:\platforms\python3.6.5\Scripts\;
E:\platforms\python3.6.5;
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
E:\Git\cmd;
E:\Git\mingw64\bin;
E:\Git\usr\bin;
C:\Program Files\dotnet\;
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;
C:\Program Files (x86)\GtkSharp\2.12\bin;
C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;
E:\TortoiseGit\bin;
%GROOVY_HOME%\bin;
%SYSTEMROOT%\System32\OpenSSH\;
E:\platforms\node10.1.0\;
E:\IDE\vs2017\VC\Auxiliary\Build;

Installing failed with error code 1 in /tmp/pip_build_root/confluent-kafka

When I try to download kafka using sudo pip3 install confluent_kafka on Ubuntu 14.04 I get error shown below. I have the newest version of librdkafka installed by sudo apt-get install librdkafka-dev python-dev which is required as it is written in prerequisites on confluent-kafka-python github. Any ideas why it doesn't work?

Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/confluent-kafka/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-no3e8l_m-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/confluent-kafka
Storing debug log for failure in /home/elastic/.pip/pip.log

Installing failed with error code 1 in /tmp/pip_build_root/confluent-kafka

When I try to download kafka using sudo pip3 install confluent_kafka on Ubuntu 14.04 I get error shown below. I have the newest version of librdkafka installed by sudo apt-get install librdkafka-dev python-dev which is required as it is written in prerequisites on confluent-kafka-python github. Any ideas why it doesn't work?

Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/confluent-kafka/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-no3e8l_m-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/confluent-kafka
Storing debug log for failure in /home/elastic/.pip/pip.log

python script runs MongoClient but not with Apache

I've installed all the requirements to work with pymongo+apache+python... but for some reason when i run this from the webbrowser it reports in the error log but it works fine from the shell with a normal ./script.py

If i comment the from pymongo.... it runs ok with the browser. Any clues?

[client ::1:60818] End of script output before headers: index.py

#!/usr/bin/env python3

import cgitb
from pymongo import MongoClient
from structures import Structures

cgitb.enable()

print("Content-type: text/html")
print()
print("""hello mundo!")

python script runs MongoClient but not with Apache

I've installed all the requirements to work with pymongo+apache+python... but for some reason when i run this from the webbrowser it reports in the error log but it works fine from the shell with a normal ./script.py

If i comment the from pymongo.... it runs ok with the browser. Any clues?

[client ::1:60818] End of script output before headers: index.py

#!/usr/bin/env python3

import cgitb
from pymongo import MongoClient
from structures import Structures

cgitb.enable()

print("Content-type: text/html")
print()
print("""hello mundo!")

Prod server serving files only when debug turned on- Django

I am trying to serve dynamically created files on my Django server. The code works fine and serves the image file from media folder on my local server. It also works and serves the image file in Production server but only when I set debug to True in Prod server.

But when I set debug to False in Prod Server, I get a file not found error (in console): GET http://thesitename/media/imgs/img.png 404 (Not Found)

The server serves the files from the /static folder, but does not serve the files from /media folder.

my settings.py looks like this:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "frontend/media/")

urls.py looks like this:

app_name = 'frontend'
urlpatterns = [ ###urls###
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Views.py looks like this:

def template_page(request, loation, par, date):
    ### generating image using pil here ###
    pil_image.save("frontend/media/imgs/img.png”)
    path_to_image_passing_to_template =  “/media/imgs/img.png”
    params = {
        'path_to_image_passing_to_template' : path_to_image_passing_to_template
    }
    return render(request, 'frontend/template_page.html', params)

html looks like this:

<img src="{{path_to_image_passing_to_template}}" />

and file structure is like this:

/backend 
    urls.py
    views.py
/frontend 
    /static
    /media
        /imgs
    /templates
        /frontend
        urls.py
        views.py
/thesite
    settings.py
    urls.py
    wsgi.py
/static

I don't understand why it should work with debugging turned on in prod server and not otherwise!!!

I have looked at several questions but did not find any query close to this kind of issue. I took some help while writing working out the dynamic media files code from this answer earlier but am stuck right now.

apache2 (mod_wsgi-express): Syntax error

I accidentally deleted the virtual environment from the apache server holding my Django website. I created new virtual env and reinstalled everything on the server but when I try to restart the server using command:

sudo /etc/mod_wsgi-express-80/apachectl restart

I get the error:

apache2 (mod_wsgi-express): Syntax error on line 155 of /etc/mod_wsgi-express-80/httpd.conf: Cannot load /www/site_name/venv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so into server: /www/site_name/venv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

I checked the venv/lib/python3.5/site-packages/ folder and there is no folder named mod_wsgi in it. Should I create the folder manually? I am new to server handling and am not sure weather this is right solution. (Earlier I had done a git clean -fd which deleted the virtual env from the server ending up in this situation.)

A piece of /etc/mod_wsgi-express-80/httpd.conf looks like this: (line 155 being the line starting with "LoadModule.." )

<IfModule mpm_prefork_module>
<IfDefine MOD_WSGI_WITH_PHP5>
<IfModule !php5_module>
Loadmodule php5_module '${MOD_WSGI_MODULES_DIRECTORY}/libphp5.so'
</IfModule>
AddHandler application/x-httpd-php .php
</IfDefine>
</IfModule>

LoadModule wsgi_module '/www/site_name/venv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so'

<IfDefine MOD_WSGI_SERVER_METRICS>
<IfModule !status_module>
LoadModule status_module '${MOD_WSGI_MODULES_DIRECTORY}/mod_status.so'
</IfModule>
</IfDefine>

Please help!

How do I configure Apache using pip install mod_wsgi? (Invalid command ‘WSGIScriptAlias’)

In the process of getting my Django app running in production, I became aware that apt-get mod_wsgi didn't install the correct version of mod_wsgi. And the advice was to pip install mod_wsgi in my virtual environment.

I'm running an AWS Small Ubuntu 16.04.4 LTS server and Python 3.5.

My virtual environment is /usr/local/pulseenv and contains mod-wsgi 4.6.4.

My vhost file (/etc/apache2/sites-available/000-default.conf) has:

<VirtualHost *:80>

    ServerAdmin [email protected]
    #DocumentRoot /var/www/html
    DocumentRoot /var/www/pulsemanager/pulsemanager


        Alias /static /var/www/pulsemanager/pulsemanager/static
        <Directory /var/www/pulsemanager/pulsemanager/static>
            Require all granted
        </Directory>

        <Directory /var/www/pulsemanager/config>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>

        WSGIScriptAlias / /var/www/pulsemanager/config/wsgi.py 
        #WSGIDaemonProcess pulsemanager 
        WSGIPythonHome /usr/local/pulseenv
        WSGIPythonPath /var/www/pulsemanager
        #WSGIProcessGroup pulsemanager
        WSGIApplicationGroup %{GLOBAL}

</VirtualHost>

But when I try to start apache, I get this error:

[email protected]:~$ systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: failed (Result: exit-code) since Fri 2018-05-04 01:35:16 UTC; 13s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 6697 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

May 04 01:35:16 ip-172-31-84-213 apache2[6697]:  * The apache2 configtest failed.
May 04 01:35:16 ip-172-31-84-213 apache2[6697]: Output of config test was:
May 04 01:35:16 ip-172-31-84-213 apache2[6697]: AH00526: Syntax error on line 42 of /etc/apache2/sites-enabled/000-default.conf:
May 04 01:35:16 ip-172-31-84-213 apache2[6697]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included
May 04 01:35:16 ip-172-31-84-213 apache2[6697]: Action 'configtest' failed.
May 04 01:35:16 ip-172-31-84-213 apache2[6697]: The Apache error log may have more information.
May 04 01:35:16 ip-172-31-84-213 systemd[1]: apache2.service: Control process exited, code=exited status=1
May 04 01:35:16 ip-172-31-84-213 systemd[1]: Failed to start LSB: Apache2 web server.
May 04 01:35:16 ip-172-31-84-213 systemd[1]: apache2.service: Unit entered failed state.
May 04 01:35:16 ip-172-31-84-213 systemd[1]: apache2.service: Failed with result 'exit-code'.
lines 1-18/18 (END)

So it seems like mod_wsgi must not be found by Apache. (Is that where the WSGI* commands are?) So how do I configure Apache using pip install mod_wsgi?

Replacing session created by apache (mod_session) using wsgi python

Currently, I have a setup of CGI script with APACHE and it is possible to replace session by response header with name set by SessionHeader directive as mentioned in below URL: https://httpd.apache.org/docs/2.4/mod/mod_session.html

Now I am moving to WSGI as CGI has a big performance issue. But I am unable to use the same session at WSGI. How we can use same SessionHeader directive name in WSGI ? I've tried with cookies, simpleCookies, and even responding with headers but no results. Any help would be appreciated. Thanks