Running Django written with python3 in Gunicorn - django

I've written a django site in python 3.2 and I want to run it by Gunicorn in my VPS with Ubuntu 12.04 OS and I faced errors for that belongs to python 2.7 but since it's not a good idea to change my default python to 3.2 in Ubuntu 12.04 I want to ask is there anyway to tell Gunicorn to run my project by python 3.2 not python 2.7?

Sure, install the other python, but don't change your ubuntu settings. When you create your virtualenv for your django project, use the -p flag to specify which python to use.
virtualenv -p /usr/bin/python3.2 [path/to/new/virtualenv/]
Alternatively, move the whole project to Heroku. There you can specify things such as python version, plus you can start ignoring a whole bunch of dev-ops stuff like this and spend more time writing your app. It's free, and you can get set up in a couple of hours.

Related

telling the cmd what version of python im using

IM trying to make a website with django and im following a tutorial that is telling me i need to tell my cmd prompt what version of python im using. this is the video https://www.youtube.com/watch?v=FNQxxpM1yOs at the 10:46 mark he says to put C:/Python35/ python manage.py runserver. I am putting thi but it is not working. I am using version 3.7 so i replaced 35 with 37 but it is still not working. can someone please helps with this.
Not sure if it's different depending on OS, but I'm on Linux and use python3 manage.py runserver since I have python 2 and 3 installed. Using just python tries to use python 2, which I'm guessing isn't the version of Django you installed. I also use pip3 when I need to.
It seems like you are on Windows, you can do where python in your shell (which is pretty similar to which command on Linux) to locate your python.
If you installed python correctly then python should be already in your $PATH, in this case, as suggested by #marsonfire, just run python manage.py runserver or python3 manage.py runserver in your project folder.

django framework runserver not working

Django server isn't working on the command: python manage.py runserver (on providing the port number as well)
I'm using windows 8, the path is set in environment variables. I've tried re-installing both python and django but it didn't help.
I share the similar problem. I solved it by just running Python 2.7x.
While working with the runiserver
python manage.py runserver --noreload
also worked for me - at least for a while. Maybe install an older version of Django?
I've not literally found a solution...
however it worked when I used python 2.7.13 (this creates a folder where you've scripts, easy_install etc., but I couldn't find a folder "Python" when I was using Python 3.6.1)

Changing default Python from 2.7.10 to 3.5.2 in terminal so I can install pip

I was hoping for some help in setting up a Python development environment on a Mac.
Background: I'm running a newly upgraded macOS Sierra 10.12.1, and setting up various parts of Python development on it. This macOS version already came with Python 2.7.10 installed - and I'd prefer to leave that alone for now.
So I installed Homebrew, and then used that in turn to install the latest python3, that is, Python 3.5.2; but I guess it's not the default for Terminal yet, since when I run the python -V command, I get this in the Terminal window:
Python 2.7.10
So now I've got at least 2 version of Python on my Mac, and that's fine I guess, but the latest Python one is not the one that is the 'default'. How do I set 3.5.2 as my default rather than 2.7.10?
(Backstory for why I want to do that... pip is not installed, i.e., when I go to Terminal and type in pip, it says:
-bash: pip: command not found
When I tried to follow the installation instructions for pip, I ran into a permissions issue, which makes sense I guess, since I don't have access to the Mac's 2.7.10 Python install, nor do I really want it at this stage. So I'd like to switch Terminal to take the new Python 3.5.2 as my default one, in which case I guess I won't have pip permissions issues...)
Thanks in advance for any help folks!
The safest solution is to create a virtual environment running python 3 and use it as development environment. Check the following links:
https://docs.python.org/3/library/venv.html
http://docs.python-guide.org/en/latest/dev/virtualenvs/

two versions of django installed in ubuntu 16.04

I have two versions installed in my envirment, django 1.8.7 and 1.10 which i have installed with pip! I want to use django 1.10 by default instead of the version 1.8.7. how can I do that ?
thank you
A good way to run multiple versions of Python programs is to use virtualenv.
Installation depends on your operating system, but there is more info here.
See this tutorial for information on how to use virtualenv with Django.
With virtualenvs, you can run multiple versions of Django that use multiple versions of Python. If you add virtualenvwrapper, you can use a simple command, like workon project1 to work on a Django 1.8 project that uses Python 2.7, or workon project2 to work on a Django 1.10 project that uses Python 3.5.
Edit: in 2020 you can do:
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install django
You can install any version of Django there that you want. That version of Django will be different than any version that might be on your system.
Read more about it here: https://docs.python.org/3/library/venv.html

How to get Django to use an updated python on Mac OS X server?

I am using Django on my Mac OS X server. Things are fine, so far. I have been using python 2.6.1 and all works well. I upgraded Python to version 2.7.3. Invoking python in the terminal brings up version 2.7.3, as expected. Checking Django using the {% debug %) reveals that Django is still using the original python 2.6.1 interpreter.
On this system, /usr/local/bin contains a symlink to ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
In /usr/bin I find the python interpreter, and from that directory, invoking ./python gets python 2.6.1 running.
My $PATH is
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/mysql/bin:/usr/local/bin
which I believe must have been altered on the python 2.7.3 install.
What is considered the optimal way to get the command line and Django using the same Python? I am considering either moving the framework version to /usr/bin and sitting a symlink in the framework to the moved new version. On the system is also a /Library/Python directory, that contains the site-packages for versions 2.3, 2.5, and 2.6. In /Library/Python/2.6/site-packages are the major goodies django, mercurial, and south.
Where are people putting things, nowadays? I mean, I know I could move things around, but I would like to anticipate where the Django project is going so future upgrades can go smoothly.
Install it against the updated Python.
Consider putting your app within a virtualenv container and specifying the version of Python when you create it - as per: Use different Python version with virtualenv