1
votes

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.

Now I have been trying to install tweepy and seem to get loads of different error messages.

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:

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:

The directory '/Users/MYNAME/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Requirement already satisfied: tweepy in ./Library/Python/2.7/lib/python/site-packages
Requirement already satisfied: six>=1.7.3 in ./Library/Python/2.7/lib/python/site-packages (from tweepy)
Requirement already satisfied: 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)
Requirement already satisfied: oauthlib>=0.6.2 in ./Library/Python/2.7/lib/python/site-packages (from 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)
Requirement already satisfied: idna<2.6,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=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)
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)

When I tried to import tweepy into idle it said "no module named tweepy"

Sorry for my longwinded explanation but I'm getting desperate...

Thank you very much for your help already!!

3

3 Answers

1
votes

One solution is to use virtualenv.

In short, virtualenv creates a separate python instance in a folder different from the computers' python installation. This allows for easy installation of packages and helps you manage dependencies better than installing everything globally with pip.

How do I do this?

First, install 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.

 $ 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 install tweepy

You can test this via the python interpreter:

 $ 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.

For example, lets say you make some python program, called ProjectAAA, which uses version 1.1 of LibraryXYZ. 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. When LibraryXYZ upgraded from 1.1 to 2.2.5, they removed and renamed a few classes and functions that you used in 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.

If you used virtualenv, you could have two separate python instances, each with their own pip and their own package installations. 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.

1
votes

I use OS X and I just successfully installed tweepy on Python IDLE using:

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.

0
votes

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

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.

A potential solution could be changing your PATH directory to the one that's listed in your error message.

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.