简体   繁体   English

通过pip和HomeBrew在Mac上使用Django Python-入门

[英]Django Python on a Mac via pip and HomeBrew - Getting Started

I am trying to get started with Python Web Programming with Django , so I installed pip first (via HomeBrew ) and now the latest version of Django , but the following happens, which I have no idea what is wrong or what I should do next. 我试图开始使用Django进行Python Web编程,所以我首先安装了pip (通过HomeBrew ),现在安装了最新版本的Django ,但是发生了以下情况,我不知道哪里出了问题或下一步应该做什么。 Could someone please help me understand what is going on + what I need to do + what commands I should issue to resolve this, etc...? 有人可以帮我了解发生了什么事+我需要做什么+应该发出什么命令来解决此问题,等等...?

$ pip --version
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

$ pip install Django==1.11.7
Collecting Django==1.11.7
  Downloading Django-1.11.7-py2.py3-none-any.whl (6.9MB)
    100% |████████████████████████████████| 7.0MB 184kB/s 
Requirement already satisfied: pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from Django==1.11.7)
Installing collected packages: Django
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  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'

This is probably because your user account doesn't have some permissions regarding the Library folder. 这可能是因为您的用户帐户对“ Library文件夹没有某些权限。

Use 采用

sudo pip install Django==1.11.7

Alternative way 替代方式

You might also use 您可能还会使用

pip install --user Django

which installs Django following the user installation scheme. 它按照用户安装方案安装Django。 This page says: 页面显示:

This scheme is designed to be the most convenient solution for users that don't have write permission to the global site-packages directory or don't want to install into it... Files will be installed into subdirectories of site.USER_BASE . 对于不具有全局site-packages目录写权限或不想安装到该目录的用户,此方案旨在成为最方便的解决方案。文件将被安装到site.USER_BASE的子目录中。


However , I think that what you are doing isn't considered best practices. 但是 ,我认为您所做的并不是最佳做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM