0

I am a Windows person, and an Ubuntu and DigitalOcean newbie. I completed the steps in

https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-12-04

and am going through

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

but it is failing at pip install django, with

OSError: [Errno 13] Permission denied: '/opt/myenv/build'

Traceback:

(myenv)jeffy@originaldjangster:~$ pip install django
Downloading/unpacking django
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/basecommand.py", line 1                         22, in main
    status = self.run(options, args)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/commands/install.py", l                         ine 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundl                         e=self.bundle)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 1153, in                          prepare_files
    location = req_to_install.build_location(self.build_dir, not self.is_downloa                         d)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 218, in b                         uild_location
    _make_build_dir(build_dir)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 1527, in                          _make_build_dir
    os.makedirs(build_dir)
  File "/opt/myenv/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/opt/myenv/build'

Storing debug log for failure in /home/jeffy/.pip/pip.log

Debug log:

jeffy@originaldjangster:~$ more /home/jeffy/.pip/pip.log
------------------------------------------------------------
/opt/myenv/bin/pip run on Tue Aug  5 14:45:38 2014
Downloading/unpacking django
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 1153, in prepare_files
    location = req_to_install.build_location(self.build_dir, not self.is_download)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 218, in build_location
    _make_build_dir(build_dir)
  File "/opt/myenv/local/lib/python2.7/site-packages/pip/req.py", line 1527, in _make_build_dir
    os.makedirs(build_dir)
  File "/opt/myenv/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/opt/myenv/build'
jeffy@originaldjangster:~$

visudo:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
jeffy   ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

I skipped the problem step and proceeded successfully until pip install gunicorn, at which point I got the same error:

OSError: [Errno 13] Permission denied: '/opt/myenv/build'

FYI: I am doing this within an activated virtualenv, as instructed.

What am I doing wrong? Thank you for helping.


The above is my primary problem. If the following is easy to answer in addition, please do. It is the step I need to take as soon as I figure the above out:

I also need to know how to upgrade from Python 2.7.6 to Python 3.4.1 (or the highest available Ubuntu-compatible release). Python was already installed--I did not install it.

I would like to only have 3.4.1. I don't want 2.7 and 3.4 side by side.

jeffy@originaldjangster:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:        14.04
Codename:       trusty
jeffy@originaldjangster:~$ python --version 
Python 2.7.6
2
  • I don't think you can just remove python 2.7 from the system. Python is used in so much of the system that it would just break a tonne of stuff. I think 14.04 comes with 2.7.6 and 3.4.0 preinstalled, you can access the latest version of python 2.x installed on your system with python2 or python3 for the latest version of python 3.x on your system, you can also use python2.7 or python3.4 to get specific. Im not to hot on virtual env's but you could probably run sudo pip install django to bypass the permission issue.
    – squareborg
    Aug 5, 2014 at 19:55
  • @Shutupsquare You're right. Check out my answer. Aug 5, 2014 at 19:57

1 Answer 1

2

Digital Ocean support:

So regardless if your user is set to be able to run all commands in visudo, you will still be required to add "sudo" to all of your commands.

Regarding Python, version 2.7 simply can not be removed. If you are wanting to use Python version 3.xx, you will need to use the command python3.


Me:

Looks like that was it. The "How to install" guide https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn does not have the "sudo" prefix before the "pip" commands, and it seems like it should. It looks like 3.4 is already installed as well. Excellent.


UPDATE

It turns out the above is not good enough. Although it installs ipython, it doesn't install it in the virtualenv--there's no ipython directory created in /opt/jenv/bin at all. When installed in this way, in my environment, anyway, starting IPython uses Python 2.7, not 3.4. (that's what it says when it starts up).

The solution is to activate the virtualenv and then install with the virtualenv's pip:

sudo /opt/jenv/bin/pip install ipython

(A reminder that without sudo, this doesn't work--see the question.) IPython is now correctly installed in the bin directory, and when started, says that it's using Python 3.4 (as long as the virtualenv was created with -p /usr/bin/python3.4).

It seems these instructions need to be changed.

2
  • Yeah, I'm pretty sure with virtual env's you shouldn't need sudo because if your permissions are setup right your doing a local install in a localised folder not `/usr/* it maybe you just need to adjust permissions on your env directory.
    – squareborg
    Aug 5, 2014 at 20:01
  • @Shutupsquare Updated my answer. Aug 5, 2014 at 21:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .