简体   繁体   English

使用pip错误消息在Mac上安装tweepy

[英]installing tweepy on Mac using pip - error message

I have recently switched laptops from Microsoft to Apple (2015 MacBook Pro) and I have been installing python libraries such as Nlkt succesfully without any issues. 我最近将笔记本电脑从微软转换到Apple(2015 MacBook Pro),我已经成功安装了像Nlkt这样的python库而没有任何问题。

Now I have been trying to install tweepy and seem to get loads of different error messages. 现在我一直在尝试安装tweepy并且似乎得到大量不同的错误消息。

After trying I pip install tweepy [error message saying "invalid syntax" in my terminal] I did some research on here and tried the below solution: 在尝试我pip install tweepy [错误消息在我的终端中说“无效语法” ]我在这里做了一些研究并尝试了以下解决方案:

import pip
>>> package_name='tweepy' 
>>> pip.main(['install',package_name])

OSError: [Errno 1] Operation not permitted: '/var/folders/t1/4g62trws5812jb97vvw5kp900000gn/T/pip-yabtGc-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'  
2
>>> 

As you can see it is still not working... 你可以看到它仍然无法正常工作......

I have also tried sudo pip install tweepy , which came up with this message: 我也尝试过sudo pip install tweepy ,它提出了这条消息:

The directory '/Users/MYNAME/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. 目录'/ Users / MYNAME / Library / Caches / pip'或其父目录不归当前用户所有,并且已禁用缓存轮。 check the permissions and owner of that directory. 检查该目录的权限和所有者。 If executing pip with sudo, you may want sudo's -H flag. 如果用sudo执行pip,你可能需要sudo的-H标志。

Requirement already satisfied: tweepy in ./Library/Python/2.7/lib/python/site-packages 要求已经满足:./Library/Python/2.7/lib/python/site-packages中的tweepy
Requirement already satisfied: six>=1.7.3 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) 要求已经满足:6> = 1.7.3 in ./Library/Python/2.7/lib/python/site-packages(来自tweepy)
Requirement already satisfied: requests-oauthlib>=0.4.1 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) 要求已经满足:requests-oauthlib> = 0.4.1 in ./Library/Python/2.7/lib/python/site-packages(from tweepy)
Requirement already satisfied: requests>=2.4.3 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) 要求已经满足:请求> = 2.4.3 in ./Library/Python/2.7/lib/python/site-packages(来自tweepy)
Requirement already satisfied: oauthlib>=0.6.2 in ./Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.4.1->tweepy) 要求已经满足:oauthlib> = 0.6.2 in ./Library/Python/2.7/lib/python/site-packages(来自requests-oauthlib> = 0.4.1-> tweepy)
Requirement already satisfied: urllib3<1.22,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.4.3->tweepy) 要求已经满足:urllib3 <1.22,> = 1.21.1 in ./Library/Python/2.7/lib/python/site-packages(来自请求> = 2.4.3-> tweepy)
Requirement already satisfied: idna<2.6,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.4.3->tweepy) 要求已经满足:id。<2.6,> = 2.5 in ./Library/Python/2.7/lib/python/site-packages(来自请求> = 2.4.3-> tweepy)
Requirement already satisfied: certifi>=2017.4.17 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.4.3->tweepy) 要求已经满足:certifi> = 2017.4.17 in ./Library/Python/2.7/lib/python/site-packages(from requests> = 2.4.3-> tweepy)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.4.3->tweepy) 要求已经满足:chardet <3.1.0,> = 3.0.2 in ./Library/Python/2.7/lib/python/site-packages(from requests> = 2.4.3-> tweepy)

When I tried to import tweepy into idle it said "no module named tweepy" 当我试图将tweepy导入空闲​​状态时,它说“没有名为tweepy的模块”

Sorry for my longwinded explanation but I'm getting desperate... 对不起我的冗长解释,但我变得绝望......

Thank you very much for your help already!! 非常感谢你的帮助!!

From looking at your error message, it appears you already have it. 从查看您的错误消息,您似乎已经拥有它。

Requirement already satisfied: tweepy in ./Library/Python/2.7/lib/python/site-packages 要求已经满足:./Library/Python/2.7/lib/python/site-packages中的tweepy

I tried replicating your issue (in both Python 2.7/3.5) and didn't run in to any issues and was able to import it in to IDLE. 我尝试复制你的问题(在Python 2.7 / 3.5中)并没有遇到任何问题,并且能够将其导入IDLE。

A potential solution could be changing your PATH directory to the one that's listed in your error message. 可能的解决方案是将PATH目录更改为错误消息中列出的目录。

export PYTHONPATH=$PYTHONPATH:./Library/Python/2.7/lib/python/site-packages

Another thing would be to consider using a virtual environment in the future to ensure that there is no conflict in your package installations. 另一件事是考虑将来使用虚拟环境来确保包安装中没有冲突。

One solution is to use virtualenv . 一种解决方案是使用virtualenv

In short, virtualenv creates a separate python instance in a folder different from the computers' python installation. 简而言之,virtualenv在不同于计算机的python安装的文件夹中创建一个单独的python实例。 This allows for easy installation of packages and helps you manage dependencies better than installing everything globally with pip. 这样可以轻松安装软件包,并且比使用pip全局安装所有内容更有助于管理依赖关系。

How do I do this? 我该怎么做呢?

First, install virtualenv 首先, 安装virtualenv

 $ pip install virtualenv

Next, create a virtual environment. 接下来,创建一个虚拟环境。 The following command will create a python instance in a folder named "foo" in the directory you execute this from. 以下命令将在您执行此目录的目录中的名为“foo”的文件夹中创建一个python实例。

 $ virtualenv foo

Now, whenever you need to install something, use the pip that is located at foo/bin/pip and the python located at foo/bin/python . 现在,无论何时需要安装,都可以使用位于foo/bin/pip和位于foo/bin/python

 $ foo/bin/pip install tweepy

You can test this via the python interpreter: 你可以通过python解释器测试这个:

 $ foo/bin/python
 Python 2.7.10 (default, Feb  6 2017, 23:53:20) 
 [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import tweepy 

Why would you want to do this? 你为什么想做这个?

If you use virtualenv, you are less likely to run into dependency issues. 如果您使用virtualenv,则不太可能遇到依赖性问题。

For example, lets say you make some python program, called ProjectAAA, which uses version 1.1 of LibraryXYZ. 例如,假设您创建了一个名为ProjectAAA的python程序,它使用了LibraryXYZ的1.1版本。 A couple months later you want to write a new, completely unrelated python program, ProjectZZZ, which uses version 2.2.5 of that same library. 几个月后,你想要编写一个新的,完全不相关的python程序ProjectZZZ,它使用同一个库的2.2.5版本。 When LibraryXYZ upgraded from 1.1 to 2.2.5, they removed and renamed a few classes and functions that you used in ProjectAAA. 当LibraryXYZ从1.1升级到2.2.5时,他们删除并重命名了您在ProjectAAA中使用的一些类和函数。 So, if you used pip and installed to the main python instance on your Mac, you won't be able to run ProjectAAA anymore, because it depends on version 1.1 but your computer has version 2.2.5. 因此,如果您使用pip并安装到Mac上的主python实例,您将无法再运行ProjectAAA,因为它依赖于1.1版,但您的计算机具有2.2.5版。

If you used virtualenv, you could have two separate python instances, each with their own pip and their own package installations. 如果你使用virtualenv,你可以有两个单独的python实例,每个实例都有自己的pip和自己的包安装。 So the environment for ProjectAAA has version 1.1, the environment for ProjectZZZ has version 2.2.5, and both can live peacefully on your computer. 因此ProjectAAA的环境版本为1.1,ProjectZZZ的环境版本为2.2.5,并且两者都可以在您的计算机上安静地生活。

I use OS X and I just successfully installed tweepy on Python IDLE using: 我使用OS X,我刚刚在Python IDLE上成功安装了tweepy:

import pip
package_name='tweepy' 
pip.main(['install',package_name])

It was pretty easy. 这很简单。

Thanks for the provision; 谢谢你的提供; now I can get on with my first extraction. 现在我可以继续我的第一次提取。

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

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