installing tweepy on Mac using pip - error message - python

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!!

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.

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.

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.
Further notes: Installing Python on Mac OS X: virtualenv

Related

Unable to import pandas in Replit.com

import pandas
So I am working on a python project and want to import pandas library on https://replit.com/~
For some reasons, it shows some attribute error when I run the project.
Does anyone know ho do I fix or manually install pandas on replit?
Attaching Screenshot of an error herewith.
Usually packages have a lot of errors in replit but you can try this: -
Pandas does actually work on repl.it - you have to install it from the package manager. To do so, click the cube on the side navigation bar and type pandas into the search box. Then click on the pandas search entry and hit the plus sign. Tell me if this works!
Or
Broken package installs can usually be fixed by,
Updating pip and installing pandas from PyPI. By default, Repl.it comes with pip version 19.3.1, but the latest available version for python 3.8 is pip-21.1.1.
~/repl$ pip -V
pip 19.3.1 from /opt/virtualenvs/python3/lib/python3.8/site-packages/pip (python 3.8)
~/repl$ pip install pandas
Requirement already satisfied: numpy>=1.16.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (1.20.2)
Collecting pytz>=2017.3
Using cached https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in /opt/virtualenvs/python3/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)
Installing collected packages: pytz, pandas
Successfully installed pandas-1.2.4 pytz-2021.1
Pandas does not work on replit at all, because a lot of modules, which Pandas needs to work properly, do not work in replit. An online Compiler is also not the best choice for doing dataprocessing, it would be better if you install an Interpreter for python on your PC.

How do I fix this error in Spyder: No module named 'flask'

Updated:
So after doing some digging I was able to find that if I add a '!' before pip it allows me to run pip inside of Spyder. (I was unable to run pip inside the console originally. That is why below you will see I ran a version check on flask in a python cmd
Here I'm trying to install the latest version of flask just to make sure I have it installed.
If I run !pip install Flask I get the following:
Requirement already satisfied: Flask in {path}\python37-32\lib\site-packages (2.0.1)
Requirement already satisfied: Werkzeug>=2.0 in {path}\python37-32\lib\site-packages (from Flask) (2.0.1)
Requirement already satisfied: Jinja2>=3.0 in {path}\spyder\pkgs (from Flask) (3.0.0)
Requirement already satisfied: itsdangerous>=2.0 in {path}\python37-32\lib\site-packages (from Flask) (2.0.1)
Requirement already satisfied: click>=7.1.2 in {path}\spyder\pkgs (from Flask) (8.0.0)
Requirement already satisfied: colorama in {path}\spyder\pkgs (from click>=7.1.2->Flask) (0.4.4)
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in {path}\spyder\pkgs (from Jinja2>=3.0->Flask) (2.0.0)
That means that flask is definitely installed and can be reached by Spyder. When I run the file the following command is run:
runfile('{path_to_folder}/{file_name}.py', wdir='{path_to_folder}')
I still don't know what is wrong with this, and I don't use Spyder very often so I don't believe it could be an environment variable that I messed with causing the issue.
Original Post:
So the issue is when I run my code in spyder I get the error below
ModuleNotFoundError: No module named 'flask'
I'm importing flask at the top of my program. Below is what I get when I run my .py file in spyder.
from flask import Flask, jsonify
I checked to make sure I have flask installed and I do. I ran python in cmd to check which version of flask I was runnning.
>>> import flask
>>> flask.__version__
'2.0.1'
I'm not sure what else could be the issue. I'm not using a virtual environment so that isn't causing an issue.
Problem
Here was the issue.
From what I can tell it's related to a known issue in Spyder 5. When I started the project that I'm currently working on I updated to the latest version of Spyder. Apparently, there is an issue with some of the dependences in Spyder 5 and that was causing the issue.
You can read more about the exact issue here
Solution
I simply downgraded to Spyder 4 until the patch for this issue is released.

Python VS Code imports not working 'No module name requests'

I'm new to python, coming from 6 months of c++ and am also new to VS Code (from VS).
My error is>
Exception has occurred: ModuleNotFoundError
No module named 'requests'
File "C:\Users\ryanb\Documents\Python\main.py", line 1, in
import requests
on anything which begins with :
import requests
this works fine in VS, but I have been encouraged to use Code. When I ran the pip command it said 'satisified'.
PS C:\Users\ryanb\Documents\Python> pip install requests
Requirement already satisfied: requests in c:\users\ryanb\anaconda3\lib\site-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ryanb\anaconda3\lib\site-packages (from requests) (3.0.4)
PS C:\Users\ryanb\Documents\Python>
I have anaconda, though I'm new to it as well, but I seem to get the problem either way.
Initially my problem was that it wouldn't find the interpreter but this was resolved after I installed add on files to visual studio (not visual studio code) and used the interpreter which came with that.
Please advise.
Thank you
You may have several python versions installed (e.g. 3.6 32-bit, 3.6 64-bit, 2.7, ...). I would recommend to "natively" install Python from https://www.python.org/ instead of using Anaconda. The problem can happen because VS code is using another Python, different than the one you installed requests. You can verify this if pip3 is installed: try pip3 --version. Anyway, you can change the interpreter VS code is using by clicking the lower bar: screenshot
Or you might just run pip3 install requests.
I would recommend you to leave just one Python installed in your machine.

Tried all means but still missing IPython

A simple line:
import IPython
The error shows:
ModuleNotFoundError: No module named 'IPython'
(It looks like a duplicated question but I did searched and tried all means but the problem persits.)
I used "pip install IPython", it gives me "Successfully installed IPython-5.8.0".
Requirement already satisfied: traitlets>=4.2 in c:\python27\lib\site-packages (from IPython) (4.3.2)
I also used "pip install ipython"
It gives me:
Requirement already satisfied: ipython in c:\python27\lib\site-packages (5.8.0)
p.s.:
The path "c:\python27\lib\site-packages" is included in the System Varaiblaes in the Environment Variable"
visual studio c++ 9.0, the version to python 2.7 is intalled
How can I have it installed? Thank you.

Error: Failed building wheel for wxpython-phoenix while installing wx

I am trying to install wxpython (I have python 3.5.2(32Bit) and Windows 10(64Bit))
I tried :pip install wx and i get: Failed building wheel for wxpython-phoenix 2 times and then a big error line-->
I also tried installing Anaconda, but it did not help.How can I overcome the problem ?
There's a lot of questions about failed installations on windows, probably because the packages are compiled when installed, and sometimes the compilation fail when the compiler is not properly configured. I admit I decided to let the specialized people handle it.
As a nice workaround, you can grab the already built distribution at the official wxpython website located here:
Python 3.5 32/64 bit windows:
https://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-win_amd64.whl
https://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-win32.whl
just download the .whl file and do for example:
C:\python35\scripts\pip install wxPython_Phoenix-3.0.3.dev2700+c524ed1-cp35-cp35m-win_amd64.whl
For linux you need to go here first
https://extras.wxpython.org/wxPython4/extras/linux/gtk3/
Then grab your linux version and do the install.
(base) fsdfsdfd#linux:~/Downloads$ pip install wxPython-4.1.1-cp38-cp38-linux_x86_64.whl
Processing ./wxPython-4.1.1-cp38-cp38-linux_x86_64.whl
Requirement already satisfied: pillow in /home/orangel/miniconda3/lib/python3.8/site-packages (from wxPython==4.1.1) (8.1.2)
Requirement already satisfied: numpy; python_version >= "3.0" in /home/orangel/miniconda3/lib/python3.8/site-packages (from wxPython==4.1.1) (1.20.1)
Requirement already satisfied: six in /home/orangel/miniconda3/lib/python3.8/site-packages (from wxPython==4.1.1) (1.15.0)
Installing collected packages: wxPython
Successfully installed wxPython-4.1.1
if does not works, please try this
sudo apt install libwxgtk3.0-gtk3-dev

Categories