2016-11-14 208 views
1

我对编码比较陌生,但觉得自己对基础知识有了很深的理解。我正在寻找使用蟒蛇来使用tweepy模块进行twitter实验,但我在安装它和其他模块时也遇到了麻烦,在命令行中使用pip。用pip安装tweepy模块

在命令行中键入pip pip install tweepy(终端在macOS Sierra上)返回此帖子结尾处的错误字符串。

如果有人可以说明为什么我不能安装任何模块,我会非常感激。

在此先感谢。

Collecting tweepy 
    Using cached tweepy-3.5.0-py2.py3-none-any.whl 
Collecting six>=1.7.3 (from tweepy) 
    Using cached six-1.10.0-py2.py3-none-any.whl 
Collecting requests-oauthlib>=0.4.1 (from tweepy) 
    Using cached requests_oauthlib-0.7.0-py2.py3-none-any.whl 
Collecting requests>=2.4.3 (from tweepy) 
    Using cached requests-2.11.1-py2.py3-none-any.whl 
Collecting oauthlib>=0.6.2 (from requests-oauthlib>=0.4.1->tweepy) 
    Using cached oauthlib-2.0.0.tar.gz 
Installing collected packages: six, oauthlib, requests, requests-oauthlib, tweepy 
    Found existing installation: six 1.4.1 
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project. 
    Uninstalling six-1.4.1: 
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 778, in install 
    requirement.uninstall(auto_confirm=True) 
    File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall 
    paths_to_remove.remove(auto_confirm) 
    File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove 
    renames(path, new_path) 
    File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames 
    shutil.move(old, new) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move 
    copy2(src, real_dst) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2 
    copystat(src, dst) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat 
    os.chflags(dst, st.st_flags) 
OSError: [Errno 1] Operation not permitted: '/var/folders/3m/f0y775rj4nj_xc8t0vntyjk80000gn/T/pip-thDOd4-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info' 
+1

好像你正在安装该软件包的全系统,而不是在virtualenv中。尝试在您的pip评论前使用sudo:sudo pip install tweepy –

+0

我遇到了完全相同的问题。即使使用sudo,也会出现同样的错误消息“The directory'/ Users/aditinarware/Library/Caches/pip/http'或其父目录不属于当前用户,并且缓存已被禁用。请检查该目录的权限和所有者。如果用sudo执行pip,则可能需要sudo的-H标志.' –

回答

0

Operation not permitted

你需要运行:

sudo pip install tweepy 
+0

感谢您的快速回复。我试过运行'sudo pip install tweepy',但是在下面的消息前面会出现相同的错误。请原谅我的无知! '目录'/ Users/dedwards/Library/Caches/pip'或其父目录不属于当前用户,并且缓存轮已被禁用。检查该目录的权限和所有者。如果用sudo执行pip,你可能需要sudo的-H标志.' –

+0

@Strobe_我有完全相同的问题,请帮忙。 –

+0

@AditiNarware看看这个链接的第一个答案http://stackoverflow.com/questions/27870003/pip-install-please-check-the-permissions-and-owner-of-that-directory –

0

您有权限问题。如上所示,您可以尝试使用sudo

2

如上所述,您需要root访问权限,其中pip存储软件包。

Python 3.x都有:

sudo pip3 install tweepy 

的Python 2.x的:

sudo pip install tweepy 

您也可以使用Git的克隆从GitHub存储库,然后手动安装:

git clone https://github.com/tweepy/tweepy.git 
cd tweepy 
python setup.py install 

或者,您可以使用virtualenv

"What if you can't install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtualenv can help you. It creates an environment that has its own installation directories, that doesn't share libraries with other virtualenv environments (and optionally doesn't access the globally installed libraries either)."

基本上它可以让你为你的每一个项目创建一个独立的环境,它对你有权限问题有帮助。

欲了解更多信息: Installing Python on Mac OS X: virtualenv