在 digitalocean 中启动 Ubuntu:pip 失败并显示“权限被拒绝”

在 digitalocean 中启动 Ubuntu:pip 失败并显示“权限被拒绝”

我是一名 Windows 用户,也是 Ubuntu 和 DigitalOcean 新手。我完成了

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

并且正在经历

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

但它失败了pip install django

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

追溯:

(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

调试日志:

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:~$

视觉:

#
# 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

我跳过了问题步骤并成功继续pip install gunicorn,直到此时我收到了同样的错误:

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

仅供参考:我正在按照指示在激活的虚拟环境中执行此操作。

我做错了什么?谢谢你的帮助。


以上是我的主要问题。如果以下问题很容易回答,请回答。这是我弄清楚上述问题后需要采取的步骤:

我还需要知道如何从 Python 2.7.6 升级到 Python 3.4.1(或可用的最高 Ubuntu 兼容版本)。Python 已安装 - 我没有安装它。

我只想使用 3.4.1。我不希望 2.7 和 3.4 并存。

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

答案1

数字海洋支持:

因此,无论您的用户是否设置为能够在 visudo 中运行所有命令,您仍然需要在所有命令中添加“sudo”。

至于 Python,2.7 版本根本无法删除。如果要使用 Python 3.xx 版本,则需要使用命令 python3。


我:

看起来就是这样。“如何安装”指南 https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn “pip” 命令前没有“sudo”前缀,但似乎应该有。看起来 3.4 也已安装。非常好。


更新

事实证明,上述操作还不够好。虽然它安装了 ipython,但没有安装它在虚拟环境中--根本没有ipython创建目录/opt/jenv/bin。以这种方式安装时,无论如何,在我的环境中,启动 IPython 使用的是 Python 2.7,而不是 3.4。(这是启动时显示的)。

解决方案是激活虚拟环境,然后使用虚拟环境点子:

sudo /opt/jenv/bin/pip install ipython

(提醒一下,如果没有sudo,这将不起作用——请参阅问题。)IPython 现在已经正确安装在 bin 目录中,并且在启动时,显示它正在使用 Python 3.4(只要使用创建了 virtualenv -p /usr/bin/python3.4)。

它似乎这些说明需要改变。

相关内容