Comenzando con Ubuntu en digitalocean: pip falla con "Permiso denegado"

Comenzando con Ubuntu en digitalocean: pip falla con "Permiso denegado"

Soy una persona de Windows y un novato en Ubuntu y DigitalOcean. Completé los pasos en

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

y estoy pasando por

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

pero está fallando en pip install django, con

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

Rastrear:

(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

Registro de depuración:

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

Me salté el paso del problema y proseguí con éxito hasta pip install gunicorn, momento en el que recibí el mismo error:

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

Para su información: estoy haciendo esto dentro de un entorno virtual activado, según las instrucciones.

¿Qué estoy haciendo mal? Gracias por ayudar.


Lo anterior es mi principal problema. Si lo siguiente es fácil de responder, hágalo. Es el paso que debo dar tan pronto como descubrí lo anterior:

También necesito saber cómo actualizar de Python 2.7.6 a Python 3.4.1 (o la versión más alta disponible compatible con Ubuntu). Python ya estaba instalado; yo no lo instalé.

Me gustaría tener solo la 3.4.1. No quiero 2.7 y 3.4 uno al lado del otro.

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

Respuesta1

Soporte de Océano Digital:

Entonces, independientemente de si su usuario está configurado para poder ejecutar todos los comandos en visudo, aún deberá agregar "sudo" a todos sus comandos.

En cuanto a Python, la versión 2.7 simplemente no se puede eliminar. Si desea utilizar la versión 3.xx de Python, deberá utilizar el comando python3.


A mí:

Parece que eso fue todo. La guía "Cómo instalar" https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn no tiene el prefijo "sudo" antes de los comandos "pip", y parece que debería tenerlo. Parece que 3.4 también está instalado. Excelente.


ACTUALIZAR

Resulta que lo anterior no es suficiente. Aunque instala ipython, no lo instala.en el entorno virtual--no se ipythonha creado ningún directorio en /opt/jenv/binabsoluto. Cuando se instala de esta manera, en mi entorno, de todos modos, iniciar IPython usa Python 2.7, no 3.4. (eso es lo que dice cuando arranca).

La solución es activar virtualenv y luego instalar con elentorno virtualpepita:

sudo /opt/jenv/bin/pip install ipython

(Un recordatorio de que sin sudo, esto no funciona; consulte la pregunta). IPython ahora está instalado correctamente en el directorio bin y, cuando se inicia, dice que está usando Python 3.4 (siempre que virtualenv se haya creado con -p /usr/bin/python3.4).

Pareceestas instruccionesnecesitar ser cambiado.

información relacionada