two versions of django installed in ubuntu 16.04 - django

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

Related

In PyCharm Django version

How can I use Django 1.11 as default version in pycharm ?
Letting you know that I'm using macOS and default Django version is 2.0.3 !
Pycharm has nothing to do with Django version. You can just install django version you need.
Use: pip3 install django==1.11
Note:
You can check your globally installed django version by typing:
python3
import django
django.VERSION
You will probably get 2.0.3 as global django version. So now you have to type:
pip3 install django==1.11
That will install django with version 1.11 as global. From now, whenever you will create new project via:
django-admin startproject your_project
Django version of that new project will be 1.11 by default
And some advice:
Next time just use virtualenv or virtualenvwrapper, by using it you will set your libraries locally for each project
You can use python virtualenv to create a custom environment for your project with django version 1.11.
https://docs.python.org/3/library/venv.html
https://www.jetbrains.com/help/pycharm-edu/creating-virtual-environment.html
In your project folder :
python3 -m venv env
source env/bin/activate
pip install django=1.11
This will create a folder named env (source command activates this environment). You may need to install all your other dependencies.
In PyCharm, under project settings Project Interpreter, select this environment.

installing python3.3.3 on virtual environment

I was using ubuntu 13.04. So python 2.7 is already installed in my system.I need to install python 3.3.3 on my system for a new project.There existed virtual environment in my system.the versions of virtual envs are
virtualenv==1.10.1
virtualenv-clone==0.2.4
virtualenvwrapper==4.1.1
distribute==0.6.49
which is installed on my /usr/local/bin path.So now I need to install python 3.3.3 on my existing environment created with these virtual envs using distribute.Is it possible to install python 3.3.3 with these versions of virtual env or whether I need to upgrade the environments? Please help me.I need the whole steps in installation procedure.
Is this code satisfied virtualenv --python=python3.3 test --distribute python 3.3
Also tell me the best version of django to be used with python 3.3 version
Tested it on my local machine - it does work.
Since Python3 support was added with django 1.5 I recommend it and everything above.
...Django 1.5 is also the first release with Python 3 support!...

Running Django written with python3 in Gunicorn

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.

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

Is there a way to install Django 1.2 and 1.3 side by side?

I need to use Django 1.2 for one of my projects.
I also already have several projects running on Django 1.3 on the same server, and I need to keep them running.
Is there a way to only use 1.2 for a specific project?
Both sites run on Apache via mod_wsgi.
Consider installing Django inside a virtualenv. This will make the installation of python modules, including Django, completely independent of the rest of the system. This way, if you have multiple virtualenvs, you can have as many versions of Django installed (one per env).
To use a virtualenv, you shold edit your index.wsgi and add the following two lines before any other line that imports or references Django:
activate_this = '/path/to/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
This is assuming that you are not using different version of the python interpreter itself, which is possible using virtualenv, but would make things quite a bit more complicated.
Yes. Django is just a regular Python module living in your site-packages. So when you import django.something, the way Python decides which version to load is by walking down the Python path (import sys; print sys.path) in order and looking for a directory called django (with something.py or something/_init_.py inside). It loads the first one it finds. So the quickest method is to modify this Python path before starting your project, which can be conveniently done with an environment variable named PYTHONPATH.
So for your Django 1.2 project, install Django 1.2 in site-packages/django-1.2 and then:
# run Django 1.2 for old app that I don't have time to update
cd ~gaearon/src/old-django-project
env PYTHONPATH=/Library/Python/2.6/site-packages/django-1.2 ./manage.py runserver
For all other (Django 1.3) projects, simply install Django as normal, which makes it the default:
# all other projects use the system default Django 1.3
cd ~gaearon/src/current-django-project
./manage.py runserver
For production servers you won't use runserver, but the PYTHONPATH will work wherever you invoke Python (i.e. flup, or manage.py runfcgi). If invoked from mod_python there is an Apache configuration directive to modify the Python path (see mod_python documentation).
Or you could use virtualenv.
When I need to do stuff like this I have found that virtualenv combined with virtualenvwrapper helps a lot.
> mkvirtualenv django1.2
> cd django-1.2-dist-dir
> python setup.py install
> mkvirtualenv django1.3
> cd django-1.3-dist-dir
> python setup.py install
Now both Django versions are installed in their own virtual environments. To use a specific one do:
> workon django1.2
or
> workon django1.3