Ubuntu 16.04 virtualenv django import error - django

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.

Related

how do solve import error in django project

ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable i have activated the virtualenv on many but yet I can't run the server
When you install Django on your computer all things go fine but when you install a Virtual environment it gets separated from all things.
Just reinstall Django in the virtual environment:
pip install Django
and then just run the command for testing:
python manage.py runsever

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.

Path issue Pip (Psycopg2) inside VirtualEnv

When using Pip (6.0.8) to install Django (1.9) and Psycopg2 (2.6.1), Django got installed in the env/lib/python2.7/site-packages folder and Psycopg2 in the env/lib64/python2.7/site-packages folder.
When I'm using command line (eg python manage.py migrate) or >>> import psycopg2, this all works fine. But when Mod_WSGI is running the application it complains that there is no module Psycopg2.
I'm able to work around this issue by adding the lib64 as a python path in my Apache conf file, but I'm pretty sure this is not the best possible way.
Any suggestions for a better solution?
Btw: I noticed by the way that Pip 7.1.2 is installing Django in Lib64 as well iso Lib.
Yes, there is with the use of --install-option. Have a look at the docs

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.

How to install Django on different version of PYTHON?

I have two python versions 2.6 and 3.0. I want to install django1.3 in python3.0's site-package directory and my default python setting is on 2.6. I also added path /usr/local/bin/python3.0 and /usr/local/bin/python3.0 into .bashrc file.
Please help me.
Django is not compatible with Python 3. You must install it in the 2.X branch.
However, what you want to achive will be easier done using virtualenv:
easy_install virtualenv
virtualenv project --python=python2.6
source project/bin/activate
pip install django
Django doesn't yet work with python3.0. So it is better you install it on the python2.6 dist-packages folder.
That said, if you had python2.7 and wanted to install django on python 2.7, while the better approach is to use virtualenv, a simple solution is to:
python2.7 setup.py install
or
easy_install2.7 django
or
/path/to/python2.7/dist-packages/pip/pip install django
easy_install virtualenv
pip install django
Sudo pip install django
Seemed to work for me!
by using pip install django --> it installs the latest version of django.
https://technicalforum.wordpress.com/2016/12/17/introduction-to-django/