12

I am new to installing new python modules.

I installed tweepy using pip install tweepy. The installation was successful and 2 folders tweepy & tweepy-3.3.0.dist-info are created in the Lib/site-packages, hence I assumed all should be fine.

However, when I went to the IDE and import tweepy. It is unable to detect the module:

>>> import tweepy
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ImportError: No module named tweepy

What is wrong?

I am running python 2.7.5.

[Update 1] I am using windows 7.

I first installed pip using another forum's suggestion (How do I install pip on Windows?). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation.

[Update 2] Using a file with import tweepy and running it, I have a similar error.

Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\xxxx\Desktop\Script1.py", line 2, in <module>
    from tweepy import Stream
ImportError: No module named tweepy

[Update 3] Typed "pip freeze" in cmd. It does show tweepy=3.3.0

C:\Python27\Scripts>pip freeze 
oauthlib==0.7.2 
requests==2.7.0 
requests-oauthlib==0.5.0 
six==1.9.0 
tweepy==3.3.0 
wheel==0.24.0

[Answer] Thanks for all the help guys, especially Cleb & omri_saadon suggestion that there might be something wrong with the file path.

I just realised that my GIS software, ArcGIS by default installed another Python into the Python27 folder, and everything is taken from that folder, C:\Python27\ArcGIS10.2, instead of C:\Python27. After I install tweepy from C:\Python27\ArcGIS10.2\Scripts, everything works well.

Community
  • 1
  • 1
Jake
  • 2,482
  • 7
  • 27
  • 51
  • 1
    How did you install it? See http://stackoverflow.com/q/27451316/ where they suggest `pip` to install it – fedorqui Jul 15 '15 at 12:55
  • If you have an Apple or Linux could you do in your command line `pip list | grep 'tw' ` so that you could confirm that you really have it installed – Papouche Guinslyzinho Jul 15 '15 at 12:59
  • Hi, I first installed pip using another forum's suggestion (http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows). basically saving the get-pip.py script and double clicking it (unable to get "python get-pip.py" to work in cmd prompt as suggested). Then, I went to cmd and nagivated to C:/Python27/Scripts and type in pip install tweepy. I remembered seeing the result as a successful installation. I forgot to mention that I'm using windows! – Jake Jul 15 '15 at 13:00
  • When you write "import tweepy" in a file and execute this file, do you then get the same error message? You might have to change/set the variable PYTHONPATH accordingly. – Cleb Jul 15 '15 at 13:04
  • Error seems pretty similar: Traceback (most recent call last): File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in __main__.__dict__ File "C:\Users\xxxxx\Desktop\Script1.py", line 2, in from tweepy import Stream ImportError: No module named tweepy – Jake Jul 15 '15 at 13:10
  • Give these details in the main question, not in comments. Please [edit] your question to clarify! – fedorqui Jul 15 '15 at 13:14
  • Oops will do! first timer here! – Jake Jul 15 '15 at 13:17
  • write pip freeze in the cmd.. do you see tweepy? – omri_saadon Jul 15 '15 at 13:20
  • Yes it did show... :( weird.. – Jake Jul 15 '15 at 13:26
  • Pull up your CMD and type `echo %PATH%`. What are the results you're getting? – Leb Jul 15 '15 at 14:52

14 Answers14

19

Try to pip uninstall tweepy

and then again pip install tweepy

Make sure you don't have several interpreters on your computer, if you have several, make sure that your pycharm(or any other editor you use) is configured with the same interpreter where you installed tweepy.

omri_saadon
  • 10,193
  • 7
  • 33
  • 58
  • 2
    Hi, I finally figured out what's wrong, after looking through at ur last statement about configuration. My Python was installed by default, while I was installing the GIS software ArcGIS, and somehow the folder was changed. I should be installing tweepy inside the folder C:\Python27\ArcGIS10.2\Scripts, instead of C:\Python27\Scripts. Everything works well after that. Appreciate your help! – Jake Jul 15 '15 at 15:00
5

I tried this command py -m pip install tweepy and worked for me

Yousra ADDALI
  • 332
  • 1
  • 3
  • 14
4

If you are using Anaconda

conda install -c conda-forge tweepy

you may also use

easy_install tweepy
Hadij
  • 3,661
  • 5
  • 26
  • 48
3

If you are using ubuntu try: sudo apt install python-pip

and then run: python3 -m pip install tweepy

I hope that helps!

harsh pamnani
  • 1,191
  • 1
  • 10
  • 14
2

The problem is that , tweepy in getting installed in the native python environment, i.e you might be able to import it in cmdline but must be getting error in jupyter notebook.

If this is the case, then you might need to install it with conda environment , with conda install tweepy. But if in this case also if you fail to install it due to conflicts errors thrown by conda do the following.....

  • Copy all the required tweepy pip files from the python environment, which you can find by running the pip install tweepy cmd which shows that the required package is already satisfied in a particular path.
  • You might be required to copy tweepy, requests, requests_oauthlib, oauthlib.
  • Paste the copied files into site-packages inside of Anaconda environment folder.

This solved the problem for me , hope it solves for you too.

Hemanth Kollipara
  • 902
  • 11
  • 16
2

If you are using conda enviroments and jupyter notebooks, you could try to install it from the notebook and restart the kernel:

!conda install -c conda-forge tweepy
1

If multiple versions of python are installed on the computer, you need to make sure under which version the package has been installed into. I have two versions of python installed on my mac, both python2 and python3 under /usr/local/lib path.

pipinstall tweepy only installs the package into python2.7/site-packages, while VSCode complies python3. Run pip3install tweepy to get the package under python3.7/site-packages so the module can be recognized by the compiler.

Gary Bao 鲍昱彤
  • 2,608
  • 20
  • 31
1

I had the same issue where after installing/ uninstalling via pip it still did not work. As a last ditch effort I actually moved the 'tweepy' folder in the '...Lib > site-packages' back to the main Python directory and 'import tweepy' then worked. No idea why this worked, but it did for me... Good luck!

Ali
  • 837
  • 2
  • 12
  • 18
1

I tried this, I was having the same error, but the thing that I did was, first installing the package using pip command, then spot the path where it got stored, then using os module change the directory to where the packages got stored, and then import it, it will work..

1

Very common error wherever your computer have different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown.enter image description here

Hashan Malawana
  • 333
  • 1
  • 2
  • 10
1

If you are using Jupyter Notebook, just run the command below in the cell of the notebook.

!pip install tweepy
Keth
  • 41
  • 3
0

If you are using Jupyter notebook on Anaconda try:

 sudo conda install tweepy

This worked for me on OSX.

0

The same for me, typing direct in the console import tweepy it works, but when I tried to run from the script it says 'No module named 'tweepy'' i tried to uninstall and install again but the solution was more simple, instead of run like

C:\script.py

I run

C:\python script.py

It works, Python version is 3.6.2 tweepy version is 3.5.0

Alekz7
  • 1
0

If you are using Jupyter Notebook, the only thing that worked for me was to first install Jupyter again

pip install jupyter

and then install tweepy

pip install tweepy
Kat
  • 475
  • 1
  • 6
  • 21