[Django]-Error when installing Django

3đź‘Ť

try using with sudo, it worked for me:

sudo pip install django
👤NITISH KUMAR

2đź‘Ť

This error is because of your account does not have any right access to the installation directory. If the installation directory is a system owned directory, you may need to sign in as a administrator or "root" account .

To sign in as a root :

sudo su

by using setup_tool you can easily upgrade the version of django. On Linux, you can install easy_install with:

sudo apt-get install python-setuptools

Then run:

 sudo easy_install --upgrade django

This will remove current django path from PYTHON_PATH, add its own path, and upgrade django to its newest version.

1đź‘Ť

Creating a vitualenv has solved this problem for me. I recently installed Python3.4 and wanted to use Django 1.8.X with this. Sudo pip install as expected allowed Django to be imported and used with the default python 2.7 but trying to import generated an error. My solution pooled from different sites – after about 3 hours of investigation yielded…

At the terminal:

$ virtualenv -p /usr/local/bin etc/pythonX.X env

this creates a virtualenv called env but specifically uses the python version that you want. to check where your python version is located $which pythonX.X then use that path with the -p flag. Check that you’re using the right python by default using $python -V. Then

$ source env/bin/activate

at this point you can pip install yourrequiredpackage

$pip install django 

and all good…running:

$python 
>>>import django
>>>django.VERSION

showed it was imported successfully.
I hope this helps – first post on S/O so hope i have the style for answering right and it helps! all commments welcome

👤jwbarker1305

0đź‘Ť

You are trying to install python at the global python level and need root permissions to install additional libraries. You can sudo pip install django to get around this.

The best practice, however, is to use virtual environments. This allows you to work on multiple python projects, each with their own collection of libraries.
https://virtualenv.pypa.io/en/latest/

It’s easy to set up:

First install pip, then virtualenv, and, if you’d like, install virtualenvwrapper:

sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
mkdir ~/.virtualenv

Add this to your ~/.profile

export WORKON_HOME=~/.virtualenv
source /usr/local/bin/virtualenvwrapper.sh

And you are set. Create a new virtual environment called “temp” with:

mkvirtualenv temp

To start working in the environment:

workon temp

From here you can pip install django as your current user.
To leave the virtualenv, simply type:

deactivate

Full instructions here:
http://virtualenvwrapper.readthedocs.org/en/latest/install.html

👤scum

0đź‘Ť

I have faced the same type of problem while installing on High Sierra. In my case, it was the pip version issue. Even

pip install –upgrade

wasn’t able to upgrade the pip version. So I have removed the old pip/pip2.7/pip3 from the folder and initiated a fresh refresh. That installed the new pip version 18.

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then,

python get-pip.py

After that, it was a cakewalk.

Before installing, check your default python version using

which python

command. In case it is 3, you are good to go. Otherwise, open the bash profile and change the default python version. (not recommended though).

Leave a comment