Running Django using python3 in Fedora - django

I have two versions of python installed in my fedora system. I installed django through pip command utility. Now to confirm my django installation through python3 using the following command
import django
print(django.get-version())
It is giving the message django not found.
But when I run it using the python2.7 shell it verifies that django has been installed. I want to run django using python3 what changes should I make?

Related

Ubuntu 16.04 virtualenv django import error

I installed django at virtualenv.
Django is installed at '/usr/local/lib/python3.7/site-packages', but that's not virtualenv's python path. so that makes django import error in virtualenv.
please help
You should always install libraries within your virtualenv. Activate it and then do pip install django again.

Can't install Django 1.11 version with python 2.7 virtual environment

I am trying to setup Django-2.0 & Django-1.11 version in my system with virtual environment.I done the Django-2.0 version with python-3 and am able to run the server.
But I am facing an issue when am able to install django-1.11 with python-2.7 it's installing Django-2.0 instead of Django-1.11
>>> import django
>>> print(django.get_version())
it's giving 1.11
django-admin startproject projectname
When I run this command it's installing Django-2.0 and my django_admin --version is 2.0
You could try using python -m django instead of django-admin. This will ensure that it is using the django install for the active virtual environment.
python -m django startproject myproject

I can't customise my Django forms using widget tweaks for an app

I installed pip3, installed Django-widget-tweaks and add widget_tweaks in INSTALLED_APPS[] in settings.py.
When I run the server, I'm getting the error:
-ImportError: No module named 'widget_tweaks'
It is possible that the pip3 script has installed django-widget-tweaks into a different version of Python than the one you're using to run Django. You may have multiple versions of Python 3 installed on your machine.
Try installing django-widget-tweaks using the same version of Python that you're using to run Django:
/path/to/python -m pip install django-widget-tweaks
Obviously make sure /path/to/python is the version you're using to start the Django server.

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

Running django in virtualenv - ImportError: No module named django.core.management?

I have installed Django after activating my virtualenv but still I am getting following error
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
If you already activated your virtualenv (source /path/bin/activate) then check if you have installed Django.
pip install django
With next command you can see if Django was installed.
pip freeze | grep django
Another thing that you can try is to remove first line (#!/usr/bin/env python) in the manage.py file.
You should check if django is installed
Activate your environment, then run the following command to see which version is installed :
python -c "import django; print(django.get_version())"
I am using virtual environment so I added this line in manage.py:
sys.path.append('./myvenv/lib/python3.5/site-packages')
in which myvenv is the name of my virtual environment and version of my installed Python is 3.5.
This solved my issued.
I found that I had Python 3.4 and 2.7 installed concurrently, and the pip install django==1.7 command automagically decided the Python 3.4 /dist-packages was where it should live. I CD'd over to the Python 2.7 directory and re-piped it... and all is well.
sudo pip install django --upgrade
worked for me, i am not having virutal environment by the way.
I had the same problem when I was running Django from inside a virtual environment and then using another terminal window ran the command
python manage.py shell without first switching to the venv.
The problem was resolved after I switched back.
I found that I could import the django module from the python interpreter, but django-admin.py could not import it when run from the command line.
I confirmed that I was using the python interpreter in my virtual environment.
I was using a 64-bit version of python. Uninstalling, and installing the 32-bit version, then re-creating my venv solved this for me.
If you're using virtualenv, you can add it to your path using sys.path.append('./myvenv/lib/python3.5/site-packages').
Try closing and opening the terminal again. That worked for me too.