A Complete Guide To setup django in other path
Installing django through pip
Well many use pip package manager for their install purpose (not my favorite).
to install django through pip you do something like:
pip install django
it will install django in a path which is not accessible by non-root users.
So you must first add the installation place for it.
pip install django --install-option="--prefix=$SOME_PLACE_WE_HAVE_ACCESS_TO" django
This $SOME_PLACE_WE_HAVE_ACCESS_TO
can be /home/user/
directory.
now login to python and do the import:
import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
What are we doing wrong????
PYTHONPATH
well as long as you have not installed django in PYTHONPATH python doesn't know where to import the module!!!
do this two steps:
BASH:
echo $PYTHONPATH
PYTHON:
import sys
print sys.path
well sys.path show the path of packages locations installed in python.
and $PYTHONPATH is empty...
The only thing you have to do is to add the path of django egg file to PYTHONPATH
for example in mine its:
/usr/local/lib/python2.7/dist-packages/Django-1.9-py2.7.egg
to add it to PYTHONPATH do this:
BASH:
export PYTHONPATH={{EGG PATH}}
which {{EGG PATH}} is the location of your django egg.
WHAT ABOUT django-admin?
well you have to run it from the place that django has set it up in somewhere it has been installed called bin
for that you can add the path of that bin (Think it might be ~/bin or any_place_you_installed/bin) to $PATH...
just like PYTHONPATH we do:
export PATH=$PATH:~/bin
ATTENTION >> : after $PATH is essential!!! to know why do a: echo $PATH
ATTENTION >> ~/bin must be django bin directory so pay attention to that.
Installing django through source
OH My god That's my favorite.
there is nothing difference with the thing up there just insted pip use setup.py...
for that you must have setuptools installed... (I think pip will install that itself if pip raises error for setuptools you must do the whole thing I told up there for django for setuptools too.)
after you installed setuptools you must do this:
./setup.py install --prefix=$PATH_YOU_DESIRE
the rest is the same...
REFERENCES
1 : Installing package through pip in other location.
2 : How to add a PATH To $PATH.