Copying your Python install into Cygwin won't work.
Python Extensions for Windows seems to be what you are after.
Otherwise, I would look at ActivePython (www.activestate.com/activepython/)* if you want to stay on Windows.
*Sorry, it will only let me put 1 link...
compiling python 2.7
./configure \
--prefix=/usr/local \
--enable-unicode=ucs4 \
--enable-shared \
LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
don't forget --enable-shared
or you may have problems later on.
compiling mod_wsgi for python 2.7
https://code.google.com/p/modwsgi/wiki/InstallationIssues
since you did a make altinstall
to install python2.7
you won't have a python-devel
package to install; so you would need the mod_wsgi
to refer to proper python.
./configure --with-python=/usr/local/bin/python2.7
# then edit Makefile if you want to change DESTDIR
make && make install
... try to start httpd ...
Starting httpd: httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 2 of /etc/httpd/conf.d/wsgi.conf: Cannot load /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so into server: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
Because we are not using the same python and we didn't link the module with any particular option to make it look in the correct place, it cannot find libpython2.7.so.1.0
, we can change that by making libtool
check the correct place.
# use LDFLAGS to tell libtool resulting lib needs to
# look for shared libs in /usr/local/lib too.
./configure \
--with-python=/usr/local/bin/python2.7 \
LDFLAGS="-R/usr/local/lib"
# then edit Makefile if you want to change DESTDIR
# e.g. DESTDIR = /opt/mod_wsgi2.7
make && make install
... try to start http again ...
Starting httpd: httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 2 of /etc/httpd/conf.d/wsgi.conf: Cannot load /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so into server: /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so: cannot open shared object file: Permission denied
That last error is because my system is running selinux and the file has the default context.
A quick look at stackoverflow tells me it is an selinux issue.
fixing selinux context
# ls -Z /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so
-rwxr-xr-x. root root unconfined_u:object_r:user_tmp_t:s0 /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so
The fix is to use the correct context, which can be found on the original mod_wsgi module.
chcon --reference /etc/httpd/modules/mod_wsgi.so /opt/mod_wsgi2.7/usr/lib64/httpd/modules/mod_wsgi.so
Best Answer
You can modify the
PATH
environment variable in your Python script before starting the shell, i.e., some variant of:Note that setting
shell=True
is very often unnecessary, and you should be aware of the implications of doing so, especially if you are callingPopen
using user-supplied data. The general problem is that data containing shell metacharacters (e.g., ">", or ";", "&") and so forth can cause unexpected behavior.UPDATE: For example, if I have a script called
/tmp/foo
and I want to run this usingsubprocess.Popen
, this works just fine:If I don't set
PATH
, then I get the expected error: