Reputation: 393
I am trying to install Django on my a new mac which I got yesterday. I am switching over from a Windows, but I didn't think that should have been much of an issue. Every time I try install either the version 1.6.5 or the development version I keep on getting the same error:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 215, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in clobber
os.makedirs(destdir)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'
Storing debug log for failure in /Users/Peter/Library/Logs/pip.log
Upvotes: 3
Views: 7534
Reputation: 51
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).
Upvotes: 0
Reputation: 1261
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.
Upvotes: 2
Reputation: 3212
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
Upvotes: 0
Reputation: 11
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
Upvotes: 1