import flask gives ImportError: No module named jinja2 - python

$ sudo /usr/bin/pip2 install flask==0.12
Requirement already satisfied: flask==0.12 in /usr/lib64/python2.6/site-packages
Requirement already satisfied: click>=2.0 in /usr/lib/python2.6/site-packages (from flask==0.12)
Requirement already satisfied: Jinja2>=2.4 in /usr/lib/python2.6/site-packages/Jinja2-2.6-py2.6.egg (from flask==0.12)
Requirement already satisfied: Werkzeug>=0.7 in /usr/lib/python2.6/site-packages (from flask==0.12)
Requirement already satisfied: itsdangerous>=0.21 in /usr/lib/python2.6/site-packages (from flask==0.12)
$ python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/site-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
ImportError: No module named jinja2
>>>
I get requirement already satisfied during install and then I get import error during import. Why is that ?

If you don't also have a /usr/lib/python2.6/site-packages/jinja2, it's possible that a prior install got interrupted. If that's the case, in your position I'd try removing /usr/lib/python2.6/site-packages/Jinja2-2.6-py2.6.egg and doing the install of flask==0.12 again.
There's a significantly newer version of Flask available (and Python, for that matter). I assume you have reasons for wanting something older.

Related

How to troubleshoot an allegedly missing module (google.oauth2)?

I wanted to experiment with connecting to Google Calendar APIs with a service account.
The example code requires google.oauth2, which for some reason I cannot import:
C:\Users\yop>pip3 install google
Requirement already satisfied: google in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (2.0.3)
Requirement already satisfied: beautifulsoup4 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from google) (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from beautifulsoup4->google) (1.9.5)
C:\Users\yop>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import google
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'google'
How can I troubleshoot this? The module seems to be installed, for the right Python version.
In contrast, consider the arrow module, which is installed the same way:
C:\Users\yop>pip3 install arrow
Requirement already satisfied: arrow in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (0.11.0)
Requirement already satisfied: python-dateutil in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from arrow) (2.8.0)
Requirement already satisfied: six>=1.5 in c:\users\yop\appdata\local\programs\python\python37-32\lib\site-packages (from python-dateutil->arrow) (1.12.0)
C:\Users\yop>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> arrow.__file__
'C:\\Users\\yop\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\arrow\\__init__.py'
The modules to install in order to import google are google-auth and google-auth-oauthlib:
pip3 install google-auth google-auth-oauthlib
After that you will be able to import google.oauth2

Importing Requests not Working Python 3.7

I'm running the latest Kali Linux with Python 3.7 and am trying to use the requests module. As you can see, I install requests but still cannot import it. Could someone help me reconcile this strange problem?
root#kali:~/Desktop# pip3 install --upgrade requests
Requirement already up-to-date: requests in
/usr/local/lib/python3.7/site-packages (2.20.1)
Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1
in /usr/local/lib/python3.7/site-packages (from requests) (1.23)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests) (2018.10.15)
Requirement already satisfied, skipping upgrade: idna<2.8,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests) (2.7)
root#kali:~/Desktop# python3
Python 3.5.6 (default, Sep 29 2018, 21:41:04)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'requests'
Thanks ahead of time for the help!
Since it appears you have multiple versions of Python installed you'll need to set your environment to use Python 3.7 (currently it's set to 3.5.6, and requests doesn't appear to be installed).
In your .bash_profile you could probably do:
alias python3=/path/to/python3.7
which should use the 3.7 version when you enter python3 ...

ModuleNotFoundError: No module named 'panda' though panda is installed on my mac os

I have installed anaconda on my mac os. But when I am trying to import panda library, It is throwing error as panda module not found.
So when I again try to install panda. It says panda already installed on machine
C27:python-programming jyoti.aditya$ pip install pandas
Requirement already satisfied: pandas in
/Users/aditya/anaconda3/lib/python3.7/site-packages (0.23.4)
Requirement already satisfied: python-dateutil>=2.5.0 in
/Users/aditya/anaconda3/lib/python3.7/site-packages (from pandas)
(2.7.3)
Requirement already satisfied: pytz>=2011k in
/Users/aditya/anaconda3/lib/python3.7/site-packages (from pandas)
(2018.5)
Requirement already satisfied: numpy>=1.9.0 in
/Users/aditya/anaconda3/lib/python3.7/site-packages (from pandas)
(1.15.1)
Requirement already satisfied: six>=1.5 in
/Users/aditya/anaconda3/lib/python3.7/site-packages (from python-
dateutil>=2.5.0->pandas) (1.11.0)
But when I try to import Panda library in my python code. It throws error
C27:python-programming aditya$ python
Python 3.7.0 (default, Jun 28 2018, 07:39:16)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import panda as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'panda'
The module name is pandas, not panda. Customarily it is imported like this:
import pandas as pd
See the 10 Minutes to pandas page for a quick introduction to the library.
You have installed pandas via pip but when trying to import it you have missed the s off the end of pandas.
import pandas as pd will work.

python 2.7 bcrypt not found after pip already satisfied

me#localhost:# sudo pip install bcrypt
Requirement already satisfied (use --upgrade to upgrade): bcrypt in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): cffi>=1.1 in /usr/local/lib/python2.7/dist-packages (from bcrypt)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in /usr/lib/python2.7/dist-packages (from bcrypt)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python2.7/dist-packages (from cffi>=1.1->bcrypt)
Cleaning up...
me#localhost:# python
Python 2.7.12 (default, Mar 19 2017, 23:18:21)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bcrypt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bcrypt
Why does pip say bcrypt is there when it obviously isn't? Lies!
Python 3 doesn't have access to it either.
me#localhost:# python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bcrypt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'bcrypt'
So I guess pip is just unreliable?
The command is now pip install python-bcrypt after looking at the README.md here (in the tar.gz after extracting).
It would be nice if someone updated these docs.

really simple pip python-twitter issue; can't import twitter

I don't know what I'm doing wrong here:
Sun Oct 14$ pip install python-twitter
Requirement already satisfied (use --upgrade to upgrade): python-twitter in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): simplejson in /Library/Python/2.7/site-packages (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): oauth2 in /Library/Python/2.7/site-packages (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): httplib2 in /Library/Python/2.7/site-packages (from oauth2->python-twitter)
Cleaning up...
Sun Oct 14$ python
Python 2.7.2 (default, Nov 17 2011, 13:22:48)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twitter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twitter
>>>
Do I need to do a virtualenv? What else could be going on? Sorry for my lack of understanding but any help is appreciated.
edit #1
trying to get tweepy working but.... possibly might have two versions of Python 2.7 here
Sun Oct 14$ pip install --upgrade tweepy
Requirement already up-to-date: tweepy in ./tweepy-1.11-py2.7.egg
Cleaning up...
Sun Oct 14$ python
Python 2.7.2 (default, Nov 17 2011, 13:22:48)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tweepy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tweepy
>>>
I think I might have two versions of Python 2.7 installed; one via homebrew and the Apple default. Is it possible that the homebrew install would put packages in /Library/Python/2.7/site-packages?
again, thx in advance
From what I've read, python-twitter:
Relies on Basic-Auth which Twitter switched off sometime between
August and September (2010). Only OAuth is supported by the API, and
python-twitter doesn't support this.
UPDATE: I just tried installing python-twitter using the exact same method you used and I am unable to import it as well. After doing some research I came across Python Twitter Tools, which I believe is python-twitter's replacement.
Installing twitter requires setuptools. It's just easy_install twitter to install it from the web.

Categories