2016-11-14 204 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