-2

I'm trying to install flask on for python3 in Centos7. It seems to be installed correctly, but it doesn't import right. There aren't any files called flask in the same folder, so it's not a problem with importing something else.

Notice that it works in python 2.7

$ python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.Flask
<class 'flask.app.Flask'>
>>> from flask import Flask
>>> exit()

But gives an error in python 3.6

$ python3.6
Python 3.6.4 (default, Dec 19 2017, 14:48:12)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> from flask import Flask
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Flask'

Has anyone run into this problem before?

I used sudo yum install flask to install it on centos7 and I used pip3 to install flask pip3 install flask

$ sudo pip3 install flask
Requirement already satisfied: flask in /usr/lib64/python3.6/site-packages
Requirement already satisfied: itsdangerous>=0.21 in /usr/lib/python3.6/site-packages (from flask)
Requirement already satisfied: click>=2.0 in /usr/lib/python3.6/site-packages (from flask)
Requirement already satisfied: Jinja2>=2.4 in /usr/lib/python3.6/site-packages (from flask)
Requirement already satisfied: Werkzeug>=0.7 in /usr/lib/python3.6/site-packages (from flask)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib64/python3.6/site-packages (from Jinja2>=2.4->flask)
MetaStack
  • 3,266
  • 4
  • 30
  • 67

1 Answers1

2

The Flask package are not at the same place for Python 2 and Python 3. Please install pip3 (This link is for 3.4, you can do same operation to 3.6) for Python 3.6 at first, then use pip3 install flask to install Flask for Python 3.6.

Yaoshicn
  • 144
  • 9
  • sorry should have mentioned I did that too – MetaStack Apr 06 '18 at 16:35
  • 1
    @LegitStack I am not sure which commands you used: `pip3 install --user flask` or `sudo pip3 install flask`. If you use the latter, you may try with `sudo python` and import again. By the way, you might try the first command, it would only install Python package for current user. – Yaoshicn Apr 06 '18 at 16:38
  • ok, so, I've never tried `sudo python3.6` until your suggestion here, and when I run python3.6 as a superuser it `from flask import Flask` correctly. so when I run the script with privileges it works otherwise it doesn't. – MetaStack Apr 06 '18 at 16:42
  • 1
    @LegitStack Yes. Because the package you have installed is for root user (with `sudo`). You may try `pip3 install --user flask` as I mentioned in last comment. – Yaoshicn Apr 06 '18 at 16:43