如果"pip install"有效,为什么要使用"sudo pip install"? (与HelloAnalytics.py有关的问题) [英] Why 'sudo pip install' if 'pip install' works? (Issues with HelloAnalytics.py)

查看:149
本文介绍了如果"pip install"有效,为什么要使用"sudo pip install"? (与HelloAnalytics.py有关的问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google提供了一个示例HelloAnalytics.py,以演示 google-api- python-client .

Google provides a sample HelloAnalytics.py to demonstrate the use of google-api-python-client.

在标题"2.下面.客户库" 他们写道:

使用pip,这是用于安装Python软件包的推荐工具:

Use pip, the recommended tool for installing Python packages:

sudo pip install --upgrade google-api-python-client

我想知道为什么在简单的pip(没有sudo)似乎可以完美工作(在Mac上)的情况下,为什么应该使用sudo:

I wonder why I should use sudo while a simple pip (without sudo) seems to work perfectly (on my Mac):

% pip install google-api-python-client
Collecting google-api-python-client
  Using cached google_api_python_client-1.9.3-py3-none-any.whl (59 kB)
Collecting six<2dev,>=1.6.1
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting google-auth-httplib2>=0.0.3
  Using cached google_auth_httplib2-0.0.3-py2.py3-none-any.whl (6.3 kB)
Collecting google-api-core<2dev,>=1.18.0
  Using cached google_api_core-1.20.1-py2.py3-none-any.whl (90 kB)
Collecting uritemplate<4dev,>=3.0.0
  Using cached uritemplate-3.0.1-py2.py3-none-any.whl (15 kB)
Collecting httplib2<1dev,>=0.9.2
  Using cached httplib2-0.18.1-py3-none-any.whl (95 kB)
Collecting google-auth>=1.16.0
  Using cached google_auth-1.17.2-py2.py3-none-any.whl (90 kB)
Collecting protobuf>=3.12.0
  Using cached protobuf-3.12.2-cp37-cp37m-macosx_10_9_x86_64.whl (1.3 MB)
Collecting pytz
  Using cached pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting requests<3.0.0dev,>=2.18.0
  Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB)
Requirement already satisfied: setuptools>=34.0.0 in ./venv/lib/python3.7/site-packages (from google-api-core<2dev,>=1.18.0->google-api-python-client) (41.2.0)
Collecting googleapis-common-protos<2.0dev,>=1.6.0
  Using cached googleapis_common_protos-1.52.0-py2.py3-none-any.whl (100 kB)
Collecting cachetools<5.0,>=2.0.0
  Using cached cachetools-4.1.0-py3-none-any.whl (10 kB)
Collecting pyasn1-modules>=0.2.1
  Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
Collecting rsa<5,>=3.1.4; python_version >= "3"
  Using cached rsa-4.6-py3-none-any.whl (47 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2020.4.5.2-py2.py3-none-any.whl (157 kB)
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Using cached urllib3-1.25.9-py2.py3-none-any.whl (126 kB)
Collecting chardet<4,>=3.0.2
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.9-py2.py3-none-any.whl (58 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
Installing collected packages: six, cachetools, pyasn1, pyasn1-modules, rsa, google-auth, httplib2, google-auth-httplib2, protobuf, pytz, certifi, urllib3, chardet, idna, requests, googleapis-common-protos, google-api-core, uritemplate, google-api-python-client
Successfully installed cachetools-4.1.0 certifi-2020.4.5.2 chardet-3.0.4 google-api-core-1.20.1 google-api-python-client-1.9.3 google-auth-1.17.2 google-auth-httplib2-0.0.3 googleapis-common-protos-1.52.0 httplib2-0.18.1 idna-2.9 protobuf-3.12.2 pyasn1-0.4.8 pyasn1-modules-0.2.8 pytz-2020.1 requests-2.23.0 rsa-4.6 six-1.15.0 uritemplate-3.0.1 urllib3-1.25.9

该样品只是过时了吗? (尽管 Python 2.7似乎使用了print,但没有()已被Google-api-python-client 弃用,其中混淆了其他人已经.)

Is that sample simply outdated? (They use print without () though Python 2.7 seems to be deprecated for google-api-python-client which confused others already.)

我解决了这个问题,但仍然得到了ModuleNotFoundError: No module named 'oauth2client'.我对丢失的sudo不是造成这种情况的原因吗?

I fixed that and still get an ModuleNotFoundError: No module named 'oauth2client'. Am I right that the missing sudo is not the cause for that?

好吧,他们没有解释VIEW_ID是什么,以及在哪里得到的.

Well, and they do not explain what a VIEW_ID is and where to get this.

推荐答案

它对您没有sudo起作用,因为您似乎在用户具有写许可权的位置安装了python.

It works without sudo for you because you seem to have python installed in a location where your user has write permissions.

Requirement already satisfied: setuptools>=34.0.0 in ./venv/lib/python3.7/site-packages (from google-api-core<2dev,>=1.18.0->google-api-python-client) (41.2.0)

这一切都取决于安装python的方式和位置. Mac OS发行版python安装在root拥有的/Library/中.因此,如果要安装新软件包,则需要使用sudo.

It all depends on how and where you install python. The mac os distro python is installed in /Library/ which is owned by root. So if you want to install a new package, you will need to use sudo.

这篇关于如果"pip install"有效,为什么要使用"sudo pip install"? (与HelloAnalytics.py有关的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆