Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@DotSlashNatalie
Copy link

I put in the C99 fixes and also added Visual Studio 2010 config files.

@ghost ghost assigned grisha Nov 8, 2013
@domruf
Copy link

domruf commented Jan 15, 2014

+1
I've also been able to compile this (windows 7, visual studio 2013, python 2.7 32bit)
I also ran a small test.

SetHandler mod_python
PythonHandler mod_python.publisher
def say(req, what='NOTHING'):
   return "I am saying %s" % what

which worked fine.
I had to change same paths, fix version.py (version.sh doesn't run on windows) and manually copy the python modules to my python installation.
But it worked.

@taylorni
Copy link

@domruf
What changes did you make to version.sh ? And was it just a simple/standard install of visual studio 13 ?

Nick

@DotSlashNatalie
Copy link
Author

You guys shouldn't need this patch for VS 2013 and up. Though I don't know what C99 features are missing form 2013.

@taylorni
Copy link

I still needed to use these changes, although i keep running into problem after problem

@grisha
Copy link
Owner

grisha commented Feb 17, 2014

@taylorni Would you be so kind as to report on your final experience with this (I'm especially curious about the comment from @nadams810 and version)? The reason why this hasn't been merged is that I don't have access to Windows and VS and can't test it on my end and so I have to rely on people who do. :)

@DotSlashNatalie
Copy link
Author

According to this article they started to add C99 features into VS2013:

http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx

(Which declaring a variable after statements is a C99 feature - and this was one of the paradigms that was used in the code).

After looking at my breakdown here: http://modpython.org/pipermail/mod_python/2013-November/026626.html

I realized there are other issues as well on Windows - sorry it's been awhile and after looking at tons of code from different languages you start to forget things :). I'm just glad I wrote that up so I know what I did to fix it.

I'd be interested to hear what problems @taylorni is running into. I know it was a uphill battle for me.

@taylorni
Copy link

@grisha

So first off i just want to make it clear that my lack off knowledge and experience is defiantly making this process harder than it should be, but I'm giving it a try anyway.

  1. Firstly I installed VC2013 and Windows SDK for Windows 8 (http://msdn.microsoft.com/en-us/windows/desktop/ff851942.aspx)
  2. set APACHESRC=[my Apache path] and ran build_installer.bat
  3. Receiving the errors
    "building 'mod_python_so' extension
    error: Unable to find vcvarsall.bat"
  4. Following this information (http://modpython.org/pipermail/mod_python/2007-May/023637.html)
    I set set DISTUTILS_USE_SDK=1 and set MSSdk=1
  5. Now I'm getting
    "c:....\pyconfig.h(68) : fatal error C1083: Cannot open include file: 'io.h': No such file or directory
    error: command 'cl.exe' failed with exit status 2"
  6. This was fixed by running:
    "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
  7. Now here comes the errors, however the C99 errors were not showing. The errors were "error: initializer element is not constant" associated with "PyVarObject_HEAD_INIT(&PyType_Type, 0)"
  8. I changed the files according to @nadams810 commit, ignoring the C99 changes.
    NOTE: requestobject.c had a few different errors, but following @nadams810 all errors were resolved
  9. Now after all the errors had been fixed (There are still alot of warnings) I get:
    "'D:..\mod_python-3.5.0\src\Version.rc(2) : fatal error RC1015: cannot open include file 'afxres.h'.
    error: command 'rc.exe' failed with exit status 1"
  10. The fix i found was to change afxres.h to windows.h in Version.rc
    http://stackoverflow.com/questions/3566018/cannot-open-include-file-afxres-h-in-vc2010-express
  11. This caused another error:
    "error RC2104 : undefined keyword or key name: MP_VERSION_STRING"
  12. So I remove MP_VERSION_STRING from Version.rc and it works.

Now this is where i am stuck, I am getting several unresolved external symbols.

@nadams810, you mentioned a fix to this, and also including the finfooobject.c into the project file, where exactly was this done ?

Overall it has been a frustrating experience so far but like I said at the start I put this down to my lack of knowledge and experience, however @nadams810 changes defiantly helped me along the way.

Nick

@taylorni
Copy link

After some more investigation this morning, and fixing a few of the Apache related 'unresolved external symbols', I have two symbols left, mp_version_string and mp_version_component. Not sure how to fix these though..

So I'm guessing what i did in step 12 is now back firing on me

EDIT: Created version.c file, included it in mod_python.c, and it fixed the problem. Now, mt.exe is having troubles.

mt.exe cannot locate the manifest built by link.exe the step before, link.exe is not showing any errors so im not sure as to why it is not there.

@DotSlashNatalie
Copy link
Author

@taylorni - I added it to the project to be compiled - http://i.imgur.com/QRXBIJF.png

Would it help if I zipped up all the libraries/headers I used to compile it? I remember I had to scour the internet for some of them.

@taylorni
Copy link

@nadams810 Yea that would be a great help, greatly appreciated

@domruf
Copy link

domruf commented Feb 18, 2014

when I successfully build mod_python.so before I opend the VS Project.
I did not use the build_installer.bat yet.

But I was also able to build the whole installer now.
Here is what I did:

  1. add version.c to modpy_src_files and replace the version.sh with a dummy
--- dist/setup.py.in@2152:1e05f4c21caa
+++ dist\setup.py.in
@@ -61,7 +61,8 @@
     raise AssertionError("unable to find @%s@ definition in %s", (option_name, config_status_file))

 def getmp_version():
-  return getoutput('./version.sh')
+    return "3.5.0"
+    #return getoutput('./version.sh')

 def getapxs_location():
     """finds the location of apxs from the config.status file"""
@@ -127,7 +128,7 @@

 modpy_src_files = ("mod_python.c", "_apachemodule.c", "connobject.c", "filterobject.c",
                    "hlist.c", "hlistobject.c", "requestobject.c", "serverobject.c", "tableobject.c",
-                   "util.c", "finfoobject.c")
+                   "util.c", "finfoobject.c", "version.c")

 class finallist(list):
   """this represents a list that cannot be appended to..."""
  1. set YY_NO_UNISTD_H in psp_flex.h
--- src/include/psp_flex.h@2152:1e05f4c21caa
+++ src\include\psp_flex.h
@@ -228,6 +228,7 @@

 #endif

+#define YY_NO_UNISTD_H 1
 #ifndef YY_NO_UNISTD_H
 /* Special case for "unistd.h", since it is non-ANSI. We include it way
  * down here because we want the user's section 1 to have been scanned first.
  1. fix the MP_VERSION_STRING in Version.rc
--- src/Version.rc@2152:1e05f4c21caa
+++ src\Version.rc
@@ -39,14 +39,14 @@
             VALUE "Comments", "Mod_python allows embedding Python within the Apache http server for a considerable boost in performance and added flexibility in designing web based applications. \0"
             VALUE "CompanyName", "\0"
             VALUE "FileDescription", "Embedding Python within Apache.\0"
-            VALUE "FileVersion", MP_VERSION_STRING "\0"
+            VALUE "FileVersion", MP_VERSION_STRING(MP_VERSION_MAJOR,MP_VERSION_MINOR,MP_VERSION_PATCH) "\0"
             VALUE "InternalName", "mod_python\0"
             VALUE "LegalCopyright", "Copyright © 2000-2002 Apache Software Foundation.\0"
             VALUE "LegalTrademarks", "\0"
             VALUE "OriginalFilename", "mod_python\0"
             VALUE "PrivateBuild", "\0"
             VALUE "ProductName", "mod_python\0"
-            VALUE "ProductVersion", MP_VERSION_STRING "\0"
+            VALUE "ProductVersion", MP_VERSION_STRING(MP_VERSION_MAJOR,MP_VERSION_MINOR,MP_VERSION_PATCH) "\0"
             VALUE "SpecialBuild", "\0"
         END
     END

The Version String problem needs a proper cross platform solution but at least you can get a working installer with these patches.

@taylorni
Copy link

Thanks for all your assistance, it is defiantly making this process alot smoother, I followed the instructions by @domruf and changed a few paths in VS2013 and it was succesful.

Now when trying to test it, im getting

ImportError: No module named mod_python.apache

And then when i try to access test.py i get:

[error] get_interpreter: no interpreter callback found.
[error] [client 127.0.0.1] python_handler: Can't get/create interpreter.

@DotSlashNatalie
Copy link
Author

@taylorni I uploaded the files here: https://app.box.com/s/orsffo3t4g6h9ftkq6p1

There should be a mod_python.so in the mod_python-master.VS (this is using older code). It was compiled for Python 2.7.5 and Apache 2.4. The include paths may need to be adjusted. If you are really frustrated I could build an innosetup package that installs the libraries/includes straight to your VS directory. This is usually not ideal or recommend but trust me I share your frustration when you don't care what's "right" you just want stuff to work.

Can you post your Apache configs somewhere so we can see how you load the module? Some pastebin type site ( such as http://paste.ubuntu.com/ ) would probably be for the best. As well as whatever sample code you are trying?

@taylorni
Copy link

@nadams810 - Here is my test code and apache config, thanks greatly for you help http://paste.ubuntu.com/6957801/

@DotSlashNatalie
Copy link
Author

Oh ok I think I see what's going on.

So first you have to stick lib/python/mod_python somewhere in your python path (dist-packages would work if you have root). Basically if you can launch a Python interpreter and run "from mod_python import apache" without an error then you are probably ok. This may be the problem - if not read on.

The only thing I see is kind of strange with your config is this:

Options FollowSymLinks AllowOverride None Order deny,allow Deny from all AddHandler mod_python .py PythonHandler myscript PythonDebug On

While many would argue against allowing / - I am not the security config police. You may configure your server however you wish - but you have been warned that other individuals may yell at you :).

Try this:

Options FollowSymLinks AllowOverride None Order deny,allow Deny from all SetHandler mod_python PythonHandler mod_python.testhandler PythonDebug On

And see if that gets you anywhere.

@taylorni
Copy link

Just confirming this is mod_python.so ? Because that is in my path but I still cannot run without getting an error.

from mod_python import apache
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named mod_python

@DotSlashNatalie
Copy link
Author

No you need these files: https://github.com/grisha/mod_python/tree/master/lib/python

apache.py is inside of that folder (mod_python) which has a constant defined of "OK".

@taylorni
Copy link

I gotcha, ok so now its saying,

from mod_python import apache Traceback (most recent call last): File "", line 1, in File "C:\Python26\lib\mod_python__init__.py", line 25, in from . import version ImportError: cannot import name version

Moving past that, It is now showing that there is no module '_apache'

@DotSlashNatalie
Copy link
Author

Hmm..this one has me stumped. @grisha will have to tell us how to generate version.py. Let me see if I can build one from Linux.

@DotSlashNatalie
Copy link
Author

Well this is defiantly one of my moments. You need to run setup.py to generate version.py. However, setup.py gets generated from configure I believe.

You could probably fake one here is what the contents should be:

# THIS FILE IS AUTO-GENERATED BY setup.py

version = "3.5.0-a09ab44"

# Some build-time constants:
HTTPD = "/usr/sbin/apache2"
HTTPD_VERSION = "2.2.22"
APR_VERSION = "1.4.6"
LIBEXECDIR = "/usr/lib/apache2/modules"
SYSCONFDIR = ""
TEST_MOD_PYTHON_SO = "/jenkins/jobs/mod_python_debian/workspace/src/mod_python.so" #NB: This is for test.py only
TESTHOME = "/jenkins/jobs/mod_python_debian/workspace/test"
PYTHON_BIN = "/usr/bin/python"

Here are the resulting files on Linux: http://jenkins.datanethost.net/jenkins/job/mod_python_debian/ws/

@taylorni
Copy link

Alright so I built a fake version.py based off those details and that seemed to fix it, now it is saying that there is no module '_apache'

I read here that "you can't import mod_python into scripts that are run from the command
line or any other context outside a running Apache server."
https://mail.python.org/pipermail/tutor/2007-May/054314.html

So that means that this is the expected result for importing Apache from the python interpreter ?

@DotSlashNatalie
Copy link
Author

I guess so :(.

Try running your script again - hopefully now that it's in your path and you have a version.py it should be happy.

@taylorni
Copy link

Yea i just ran it again and its giving me what looks like the test handler information e.g General Information,Request input headers,Request environment... etc.

So it looks like it was succesful.. :/

But how do i get it to run my original script ?

@DotSlashNatalie
Copy link
Author

Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
AddHandler mod_python .py
PythonHandler myscript
PythonDebug On

Preferably outside of your root HD :P ie

<Directory "/local/htdocs/python">
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
   AddHandler mod_python .py
   PythonHandler myscript
   PythonDebug On 
</Directory>

@taylorni
Copy link

Thank-you very much! Its finally working, thank you for being so patient with me haha!

@DotSlashNatalie
Copy link
Author

I feel like there should be a celebration with beer and cake.

@taylorni
Copy link

One final question, if want to get this onto another computer that has the same version of Apache and python, can I move the files across and go from there or do i need to re-compile with VS on the other machine ?

@DotSlashNatalie
Copy link
Author

You should be able to copy the compiled mod_python and Python libraries to the other computer without recompiling. Just as long as Apache versions are the same (or close) and Python versions are the same (or close).

@matthauck
Copy link

What is preventing this from being merged in? I am looking to use mod_python on an apache windows project coming up soon, and it'd be nice to not have to build off a fork... though it'd be even better if there was a released version w/ windows support =)

@grisha
Copy link
Owner

grisha commented Jul 16, 2014

@matthauck not being able to test this myself, I sense from the comments that there's still a few things that need to be fixed?

@matthauck
Copy link

Yeah I realized this later when I tried to do it myself and couldn't quite get it to compile. =T

On Jul 16, 2014, at 6:36 AM, Grisha Trubetskoy notifications@github.com wrote:

@matthauck not being able to test this myself, I sense from the comments that there's still a few things that need to be fixed?


Reply to this email directly or view it on GitHub.

@DotSlashNatalie
Copy link
Author

What is the problem you are having when you try to compile?

@matthauck
Copy link

I don't remember the exact message and have since abandoned this approach,
so I'd have to look it up later and try it out again, hopefully this time
with a bit more experiencing compiling apache modules... =)

On Wed, Jul 16, 2014 at 5:12 PM, nadams810 notifications@github.com wrote:

What is the problem you are having when you try to compile?


Reply to this email directly or view it on GitHub
#14 (comment).

Matt

@DotSlashNatalie
Copy link
Author

@matthauck You can download all the libraries you will need + sources here: https://app.box.com/s/orsffo3t4g6h9ftkq6p1

They were not very obvious to acquire. Visual Studio is a really awesome IDE (imo anyways) but they still don't provide a way for developers to note dependencies and where to get them.

@DotSlashNatalie
Copy link
Author

All - I have (finally) created a jenkins slave for Windows builds. This is built using Visual Studio 2010 https://srchub.org/jenkins/job/mod_python-Windows/lastSuccessfulBuild/artifact/src/Release/ and using the code from my fork.

There are many warnings ( https://srchub.org/jenkins/job/mod_python-Windows/lastSuccessfulBuild/console ) but it does compile and spit out an Apache module. However - automatically testing the module is whole other challenge.

@matthauck feel free to download the pre-built module if you still are looking to use mod_python on Windows

@matthauck
Copy link

thanks so much @nadams810. The ship has sailed for this project as I've actually gone ahead and written the module we needed in C instead. Perhaps for a future project. =)

@grisha grisha closed this May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.