Apache Config - Multiple python versions - python

I have a couple versions of python on my box. My app uses python 2.7 which is found in /usr/local/bin/python. Apache seems to be using an earlier version in /usr/bin/python. How can I configure Apache to use a later version of Python for my app?

To use with Python 3, you need to install the right mod_wsgi for python 3.
On Debian or Ubuntu : sudo apt-get install libapache2-mod-wsgi-py3.
For older versions of Python, when installing mod_wsgi, type : ./configure --with-python=/usr/local/bin/python2.5 for version 2.5 for instance.

You can't. Either rebuild mod_wsgi against the other version of Python, or change the shebang line in your CGI scripts to the other executable.

I could be mistaking, but whatever user apache is started with has a profile which likely has the search path in it. You could change the search path to search /usr/local/bin before /usr/bin, though this is not an ideal approach. Whatever default shell is set for the account used by Apache, just check that you have an rc-file for that shell, and if not, create one.

Related

Which mod_wsgi Binary to download?

1) I am trying to setup a WAMPServer and am stuck on which file I need to download from the site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
I am using: Windows 7(64 bit), Apache 2.4.9 and Python 2.7.
2) Also, many of the tutorials I have seen on the matter say to download a .so file. However the above link contains .whl files?
I've been using this https://stackoverflow.com/a/20128269/2268507 as a guide.
I would really appreciate it if someone could shed some light on these two matters.
Thank you for your help.
That page on the gohike site tells you to go read:
https://github.com/GrahamDumpleton/mod_wsgi/blob/master/win32/README.rst
Did you do that?
That page for mod_wsgi explains what version you should use for what. It does this in reference to the binaries that the mod_wsgi downloads list has, but if you understand what Python wheels are then you can use those from the gohike site as well.
UPDATE
Note that details at this URL are obsolete. You should use pip install as described at:
https://pypi.python.org/pypi/mod_wsgi
Once installed, run mod_wsgi-express module-config to display config you should add to your Apache configuration file to load mod_wsgi that you installed using pip install.
Yes, read the Graham's [Git] and take a look at paragraph:
"
Note that Apache Lounge never made available any Win64 VC9 binaries for Apache 2.4. This means that technically there is no combination available for correctly running mod_wsgi with a Win64 VC9 version of Python 2.6 or 2.7.
History shows that users simply don't want to accept this and don't want to understand that mixing VC9 and VC10 binaries are not guaranteed to work.
"
See that? don't use Python 2.6 or 2.7 in Win64, Apache doesn't support the module for you.
But you can still download the ".so" file in here , just found which is the best and suit for you and install it into Apache. This is the tutorial how to install mod_wsig to Apache and XAMPP. Good Luck!
Rian Hariadi, Jakarta Coding

uwsgi specify python binary

On our production server we are running Ubuntu 12.04, to make sure that our application is running in a predefined consistent environment we use Pythonbrew to compile a custom Python. I have created a user that is going to be running our API server, the user has his own Python 2.7.2 environment created with Pythonbrew, with the necessary packages installed using pip.
I've also installed uWSGI on the system, it's going to wrap the API application and make it available to Apache via mod_wsgi. The problem is that I can't get uWSGI to use the correct python binary. The current config looks like this:
[uwsgi]
socket = 127.0.0.1:3031
processes = 4
chdir = /home/app/
pythonpath = /home/app
gid = 1002
uid = 1002
module = api
callable = APP
enable-threads = true
When I try to run this config on the terminal with:
uwsgi --ini app.ini
It fails to import some module. This module is installed only in the Pythonbrew environment that the API user is using. The problem is that uWSGI is using the default python binary in /usr/bin.
One solution is to use a separate uWSGI installed using pip in the API user's environment, but I really want to use the system's uWSGI because it integrates better with the OS.
Is there any way to specify which Python binary uWSGI should use, other then by installing a separate one? If I have to install a separate instance of uWSGI, what is the best way to have it start on system boot?
Edit: just realised that it is probably not using the python binary, but just lining against it's library, so there is no way for me to use the default installation of wsgi, and the non-default python. But the question still remains, what is the best way to integrate a custom built uWSGI into the system.
uWSGI (as well as mod_wsgi) does not use the python binary, but the python shared library, so you have to link the uWSGI python plugin with the specific library of the pythonbrew user.
There are a lot of tricks to accomplish that (expecially if the pythonbrew python version matches the system version), the first one popping into my mind is specifying the pythonbrew user's prefix in its config file with
env = PYTHONHOME=path
By the way, is not better to use virtualenvs instead of full python installations for your users ?
I've run into this issue as well. It seems that uWSGI binds the Python 3 runtime during install. Once you've pip installed a version, it uses the cached wheel (hence cached Python version).
I've found this will fix it by forcing a rebuild of the binary, at least on Ubuntu:
$ pip uninstall uwsgi
$ pip install uwsgi --no-cache
$ COMMAND_TO_RESTART_UWSGI
I had this problem on Ubuntu 18.04 (so a tad bit newer than when the question was asked) and remembered that the [uwsgi] section of the configuration file contains the long command line switches.
It appears that uwsgi in the version that is packaged for Ubuntu 18.04.4 defaults to using the python plugin, which means Python 2.x in this case.
And so I managed to configure my apps by setting them to use the python3 plugin:
[uwsgi]
plugin = python3
This requires the uwsgi-plugin-python3 package to be installed. In case of Ubuntu 18.04 this defaulted to Python 3.6 and hence the above plugin line could also have been:
plugin = python36
You can test if it works with a given plugin by running uwsgi from the command line like so:
uwsgi --plugin python3 -s :0

Python 2.7.1 can't see Twisted

I have a new MacBook Pro running OS X 10.6.6 / Snow Leopard -- which ships with Python 2.6, although I have installed 2.7.1
Unfortunately, this doesn't seem to see the Twisted install in the 2.6/Extras/lib/python/twisted directory, as I find I'm unable to import modules that I can see are present in that directory.
"which python" returns "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
and running python returns the same: "Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)"
I have added the twisted directory (absolute) to sys.path, and I have added it to .bash_profile, which now consists of the following:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
PATH=$PATH:/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted
export PATH
Any ideas how I can get 2.7.1 to see the Twisted install? Or am I trying to do something that just can't be done?
thanks.
You'll need to install Twisted into your Python 2.7 installation somehow. The "2.6" in that path should be a hint that you shouldn't be trying to tell Python 2.7 about it. Among other things:
Extension modules are not compatible between python versions. You may get a segfault if you try to use them.
Bytecode formats are not compatible between python versions. Python will fall back to parsing '.py' files, which is slower.
If you're using an operating system that ships with Python 2.6, there is a good chance that the version of Twisted included is not compatible with Python 2.7, since Python 2.7 may not have been out yet when it was released.
You'll have to install twisted using python 2.7.
Also, python doesn't look up what's in the PATH variable for imports, it looks in PYTHONPATH. But just putting your python 2.6 folder in your pythonpath isn't a very good solution.
Create an environment using virtualenv.
Install Twisted in your newly created environment using pip.
You need to set up an environment for your new Python 2.7 or use the OS installed 2.6.
OS X ships with NumPy for example, but your new Python 2.7 will not 'see' it.
The best solution (IMHO) is this:
o Don't change the OS default Python AT ALL!
o Install Python 2.7, 3.0 as you wish with the system Python first in the path
o Use virtualenv to set up a personal Python environment -- a sandbox. Install twisted into that.
o Install libraries into the environment you are going to use for the job. Might mean duplicates.
o Use your shebang to execute the proper Python

installed new version of python, but django still uses system default

On Dreamhost, I did the following
installed Python 2.7.1 in my ~/opt directory,
added export PATH=$HOME/opt/bin/:$PATH in my .bash_profile
verified with python --version that 2.7.1 was default
installed setuptools 0.6c11-py2.7
installed Django 1.2.4 with /path/to/python2.7 setup.py install
verified version 1.2.4 with import django and django.VERSION in python shell
wget http://wiki.dreamhost.com/django-setup.py
python2.7 django-setup.py in my site directory ("site.com")
intentionally put a syntax error in ~/site.com/project/urls.py
visited the site in web browser and the error page still says I'm using Python 2.5.2
Why does my Django refuse to use my new version of Python?
According to this, installing-django-with-python-2-5-and-not-with-the-default-version-of-python, the problem might be with mod_wsgi (or I think passenger in my case (but I don't actually know if they do the same thing)).
Should I try to compile mod_wsgi, compile passenger_wsgi, install virtualenv, all of the above, none of the above, A and C, B D and E, or something else altogether?
Maybe you can change the WSGIPythonExecutable directive in your mod_wsgi configuration?
To configure Passenger's Python interpretter, you can follow these steps.

Install Trac on 64bits Windows 7

I'm configuring a new Developing Server that came with Windows 7 64bits.
It must have installed Trac with Subversion integration.
I install Subversion with VisualSVN 2.1.1, clients with TortoiseSVN 1.6.7 and AnkhSVN 2.1.7 for Visual Studio 2008 SP1 integration.
All works fine! my problem begun when going to Trac installation.
I install python 2.6 all fine.
Trac hasn't a x64 windows installer, so I installed it manually by compiling it with python console (C:\Python26\python.exe C:/TRAC/setup.py install).
After that, I can create TRAC projects normally, the Trac core is working fine. And so the problem begins, lets take a look at the Trac INSTALL file:
Requirements
To install Trac, the following software packages must be installed:
Python, version >= 2.3.
Subversion, version >= 1.0. (>= 1.1.xrecommended)
Subversion SWIG Python bindings (not PySVN).
PySQLite,version 1.x (for SQLite 2.x) or version 2.x (for SQLite 3.x)
Clearsilver, version >= 0.9.3 (0.9.14 recommended)
Python: OK
Subverion: OK
Subversion SWIG Python bindings (not PySVN):
Here I face the first issue, he asks me for 'cd' to the swig directory and run the 'configure' file, and the result is:
C:\swigwin-1.3.40> c:\python26\python.exe configure
File "configure", line 16
DUALCASE=1; export DUALCASE # for MKS sh
^
SyntaxError: invalid syntax
PySQLite, version 1.x (for SQLite 2.x) or version 2.x (for SQLite 3.x):
Don't need, as Python 2.6 comes with SQLLite
Clearsilver, version >= 0.9.3 (0.9.14 recommended):
Second issue, Clearsilver only has 32bit installer wich does not recognize python installation (as registry keys are in different places from 32 to 64 bits).
So I try to manually install it with python console. It returns me a error of the same kind as SWIG:
C:\clearsilver-0.10.5>C:\python26\python.exe ./configure
File "./configure", line 13
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
^
SyntaxError: invalid syntax
When I simulate a web server using the "TRACD" command, it runs fine when I disable svn support but when I try to open the web page it shows me a error regarding ClearSilver is not installed for generating the html content.
AND (for making me more happy) This TRAC will run over IIS7, I mustn't install Apache...
I'm nearly crazy with this issue... HELP!!!
Just export Register from [HKEY_LOCAL_MACHINE\SOFTWARE\Python] to [HKEY_CURRENT_USER\Software\Python].
It's happens because trac only see the [HKEY_CURRENT_USER\Software\Python] and you installed the python "For all users"
I would expect that Trac on Windows instructions should work on x64, even if they're 32-bit packages. Have you tried this and failed?
Subversion SWIG Python bindings:
configure is not meant to be run by Python; it's meant to be run with a POSIX sh, like Bash or ksh. However, if you read subversion/bindings/swig/INSTALL you'll find that the installation instructions for Windows do not use configure; instead, Visual Studio and gen-make.py are used.
Note that your bindings should match your installed Subversion.
Clearsilver:
Likewise, configure is meant for a sh, not Python. Clearsilver compilation instructions for Windows can be found in clearsilver/python/README.txt.
Looks like I'm not the only one trying to install Trac on Win 7 64-bit, only to see the install crash and burn.
One problem is the lack of installed registry entries for Python on Win x64, which I was able to find via a web search. The problem was identified months ago, but unfortunately no patch release has been made available.
I was almost ready to give up on Trac, but the information here has given me new hope. Thanks all!

Categories

Resources