i have a problem with virtualenvs and django. Apparently i just dont get how they are supposed to work.
I installed python 2.7.3 ucs2 in /opt/bin/python and it works just fine
I installed virtualenv and virtualenvwrapper and created virtual environment named py273ucs2 so when i type workon py273ucs2 i get correct virtual environment.
when i create python script with
#!/home/alan/python/virtualenvs/py273ucs2/bin/python
import sys
print sys.maxunicode
i get 65535 which is correct for ucs2 python.
at same time i have no idea how to use correct virtualenvironment for my django app so i could use ucs2 python not ucs4 one. I tried creating one test project with virtualenvwrapper.django thinking that its wsgi file or manage.py would give me hints about how to start wsgi script with correct environment - no such luck.
I found this site:
http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/
which basically (in addition to other things that i already did) tells me to add this into my wsgi file :
site.addsitedir('/srv/python-environments/saltycrane/lib/python2.5/site-packages')
which in my case is:
site.addsitedir('/home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages')
Tried - no luck.
Then there is such page:
http://www.gyford.com/phil/writing/2011/06/27/virtualenv-webfaction.php
In addition to last page it suggests i add:
activate_this = os.path.expanduser("~/.virtualenvs/my_env_name/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
which in my case is:
activate_this = os.path.expanduser("/home/alan/python/virtualenvs/py273ucs2/bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
again no luck.. view
def base(request):
return HttpResponse(sys.version+' maxunicode ' +str(sys.maxunicode))
prints out python version 2.7.2 and maxunicode 1114111 not 65535.
Then there is this message here at stackoverflow:
How does django work with virtualenv?
which suggests i add params in httd.conf - also tried and also not working.
So honestly - im not getting this. Perhaps the version is supposed to remain 2.7.2 not become 2.7.3... then whats the point of virtualenvs... Or im doing something wrong and not getting something from those examples. I also checked wsgi wiki about virtualevns:
http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
and modified my httpd.conf to:
WSGIPythonHome /home/alan/python/virtualenvs/py273ucs2
WSGIPythonPath /home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages
WSGIDaemonProcess printer user=alan group=alan processes=5 threads=5 python-path=/home/alan/python/virtualenvs/py273ucs2/lib/python2.7/site-packages
WSGIProcessGroup printer
WSGIScriptAlias / /home/alan/projects/printer/printer.wsgi
Nothing. Still see python 2.7.2 in view...
could someone help me out please :)
Alan
Edit1: answer to comments:
1)
I have to install/compile new mod_wsgi if i want to use virtualenvironment? why?
2)
if i do:
alan#alan:~$ workon py273ucs2
(py273ucs2)alan#alan:~$ cd projects/printer/
(py273ucs2)alan#alan:~/projects/printer$ python manage.py runserver
Validating models...
0 errors found
Django version 1.3, using settings 'printer.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[08/Jul/2012 05:01:00] "GET / HTTP/1.1" 200 68
then my view shows me:
2.7.3 (default, May 16 2012, 10:58:59) [GCC 4.6.1] maxunicode 65535
Edit2: Thanks to the help of Graham Dumpleton at modwsgi google group i managed to install mod_wsgi for ucs2 python (https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg).
But when i start this site i still get
2.7.2+ (default, Oct 4 2011, 20:41:12) [GCC 4.6.1] maxunicode 1114111
not
2.7.3 (default, Jul 9 2012, 13:32:29) [GCC 4.6.1] maxunicode 65535
Btw apache error log prints out this:
[Mon Jul 09 14:13:19 2012] [warn] mod_wsgi: Compiled for Python/2.7.3.
[Mon Jul 09 14:13:19 2012] [warn] mod_wsgi: Runtime using Python/2.7.2+.
Final edit:
There were several problems with how the mod_wsgi was supposed to be installed. You can find out all necessary info when you follow this link : https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg.
But after those problems the point was that the way Ubuntu python installation is made it conflicts with other pythons (not the best explanation probably but you will find very good explanation by Graham Dumpleton if you follow the link above). Virtual python and mod_wsgi started all working when i removed libapache2-mod-python package. It caused other problems, but those problems are caused by the way ubuntu and its python package are set up.
So if you are ubuntu user and happen to find same problem, then this page and Graham Dupmpletons Huge efforts will probably help you too.
Duplicate of:
https://groups.google.com/forum/?fromgroups#!topic/modwsgi/F5Wn4uWrQAg
Issue documented at:
http://code.google.com/p/modwsgi/wiki/InstallationIssues#Mixing_32_Bit_And_64_Bit_Packages
Use '--enable-shared' when configuring/installing Python.
You can't install a virtualenv of a python version you don't have already installed.
The point of virtualenv is to isolate your packages. If you create a virtualenv with --no-site-packages. It won't use the packages already installed on the system. In other words, it means you can install multiple version of each package for one pythone binary.
Having virtualenv also make it easier for development since you don't require root access to install packages using python setup.py or pip install.
It's not really clear from what you're posting, why it isn't working.
to activate a virtualenv. You have to do
source path/to/env/bin/activate
When running scripts from config, pointing out where python is located should be enough. If you do add_site_package, it is probably only adding to the python by default and not the one you wanted.
If nothing works, you might be able to do that. It should solve your problem if nothing requires the other python executable.
using which python, you should be able to know where is located the current python executable.
You could replace the symlink for the default python to your python2.7.3ucs. But I can't promise it's not going to break something somewhere. Since some programs may depend on that particular python2.7.2
edit
Apparently, your problem is definitely not with virtualenv. But with mod_wsgi. Here is a site that describe how to compile mod_wsgi for your desired python version.
http://technomilk.wordpress.com/2011/08/10/running-our-django-site-with-mod_wsgi-and-virtualenv-part-2/
this line:
$ ./configure --with-python=/home/isigma/.pythonbrew/pythons/Python-2.7.2/bin/python
This is where you put the path to your python version and then follow the steps. And hopefully it will work like butter.
edit 2
If nothing else work, it might mean you have to check for alternatives to mod_wsgi.
Here is a good one.
http://projects.unbit.it/uwsgi/wiki/Example
edit 3
Create a new virtualenv like that
virtualenv --no-site-packages --python=/opt/bin/python
Related
I'm using trac 1.2 on windows. Their documentation says it requires python2, so I pip install'd it with python2 x64, and spent a lot of time configuring some trac environments. Now I want to run trac through apache httpd so I can set it up with microsoft active directory, so I figured, okay, let's try mod_wsgi. I read this mod_wsgi documentation which mentions that python2 is built with VC9, and that apache, mod_wsgi, python binaries need to be consistent architecture throughout. So that means, for me, VC9, x64 for all. I installed the VC9 runtime from here. For mod_wsgi, I pip installd it using the mod_wsgi‑4.6.4+ap24vc9‑cp27‑cp27m‑win_amd64.whl file from here to avoid having to install VS2008's entire toolchain. Now I guess I need apache x64 VC9. The apache binary closest to VC9 I could find was VC10 here which says it loads VC9 modules, so I went ahead and tried it. I ran mod_wsgi-express module-config which gave me
LoadModule wsgi_module "c:/python27/lib/site-packages/mod_wsgi/server/mod_wsgiNone"
WSGIPythonHome "c:/python27"
The first line wasn't right, since httpd complained it couldn't load the module, so I changed it to
LoadModule wsgi_module "c:/python27/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd"
I verified that that module exists at the specified path, and ran httpd which still error'd out with
httpd: Syntax error on line 179 of C:/Apache24/conf/httpd.conf: Cannot load c:/python27/lib/site-packages/mod_wsgi/server/mod_wsgi.pyd into server: The specified module could not be found.
So I guess the VC10 x64 apache binary I downloaded isn't backwards compatible with VC9 x64 mod_wsgi.
Does this mean I now need to build my own VC9 x64 apache binary? There must be a simpler way to achieve running trac 1.2 within an apache web server, right? Unfortunately, it's not as obvious to me. Any help is appreciated. Also, let me know if I need to clarify any other detail.
I'm trying to create a Django app with WebSockets on a Raspberry Pi 2 using django-websocket-redis pip package. /manage.py runserver doesn't seem to work (got 404 calling /ws/ although it's set by WEBSOCKET_URL = '/ws/' in settings.py), I wanna try a standalone uWSGI server like described here in the official docs.
When I run uwsgi, I got strange errors. I think this is caused by a wrong python version. The output of uwsgi show me that Python 2.7 is used:
Python version: 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170124]
But I need Python 3 (exactly 3.5) for my project. I changed the default python environment, so that the python comamnd points to python 3.5 instead of 2.7. Additionally, I passed the version using --plugin switch like this:
uwsgi --http :9090 --plugin=python35 --wsgi-file wsgi.py
I also used pip3for all pip packages to make sure that no 2.x packages were used. This seems having no effect, cause my script breaks and uwsgi show me that Python 2.7 is used...
install this:
sudo apt-get install uwsgi-plugin-python3
I installed the Windows (32bit) BitNami DjangoStack 1.4.1.0 and elected not to install the python that came with it as I already have Python 2.7 installed.
I got the error below and also an internal server error when I clicked on the button in the introduction web page (so Appache is running ok)
enter code here
[error] mod_wsgi (pid=3990): Target WSGI script '/opt/bitnami/apps/django/scripts/django.wsgi' cannot be loaded as Python module
I found a similar question but that related to installing on Amazon. Also following through the answers it appeared that the problem is that the wsgi had been compiled against the wrong python version.
I then uninstalled BitNami and re-installed using the python version that was provided - still the same message.
I don't see how the wrong python version can be the problem if the BitNami package is self contained, i.e. comes with all the bits needed to run.
In case my previously installed version was causing the problem I remove it from the PATH environment variable.
Also the documentation for Windows seems wrong. django.conf and django.wsgi are not where the docs say they are (\Users\user\BitNami SDjangoStack projects\apps). In fact the only thing in that directory is the new project I selected on installation - no apps directory. I found the files in the BitNami directories.
Also when I typed python in the BitNami console I got python 2.7.3, not 2.7.2 which is listed in the installation guide.
I thought this package would be wonderful to help me get a production Django site running. It is now ready in the development phase to go live for testing.
What do you exactly mean with not installing Python? BitNami DjangoStack is self contained in the sense that it includes its own Python and its dependecies. Also you mentioned that you are running it on Windows but the path /opt/bitnami is the default path when installing as root in Linux. What exact options did you select during the installation?
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.
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.