phillipsK
phillipsK

Reputation: 1516

Installing flask; python script still cannot import

I have tried every command line installation possible in an attempt to install flask. I have followed the instructions from http://flask.pocoo.org/docs/installation/

After sudo easy_install virtualenv:

Searching for virtualenv
Best match: virtualenv 1.11.6
Adding virtualenv 1.11.6 to easy-install.pth file
Installing virtualenv script to /usr/local/bin
Installing virtualenv-2.7 script to /usr/local/bin

Using /usr/local/lib/python2.7/dist-packages
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

after pip-install flask:

Requirement already satisfied (use --upgrade to upgrade): flask in ./python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in ./python2.7/dist-packages (from Jinja2>=2.4->flask)
Cleaning up...

However after . venv/bin/activate:

bash: venv/bin/activate: No such file or directory

I do know how to navigate around the terminal and create directories. I am uncertain how to process this command and/or activate virtualenv. I cannot find this directory or perhaps the sudo/pip commands were intended for a directory not defaulted on my drive?

I try and run a python script using flask, and of course:

Traceback (most recent call last):
  File "testingflask.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask

Here is the script: testingflask.py

from flask import flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

I have tried apt-get install python-flask as well

Upvotes: 0

Views: 2949

Answers (3)

Nava
Nava

Reputation: 6556

One more thing to try

  • know your python path where site-packages are stored
  • download the flask module and extract it
  • copy the extracted folder and paste it into your python packages directory(mostly site- packages/dist-packages for me :/usr/lib/python2.7/dist-packages) [remember root only can do this]
  • open your python shell
  • and check "import flask"

know the location of your library files:

In [1]: import sys

In [2]: sys.path
Out[2]: 
['',
 '/usr/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
 '/usr/lib/python2.7/dist-packages/IPython/extensions']

Upvotes: 0

Mathias
Mathias

Reputation: 6839

Did you run virtualenv venv ? I mean do you have a venv folder in your project? I guess you missed that step!

  1. $ sudo easy_install virtualenv or sudo easy_install virtualenv
  2. $ mkdir myproject
  3. $ cd myproject
  4. virtualenv venv

I you follow those steps you should have a venv directory in myproject and the command $ . venv/bin/activate will work

Upvotes: 0

Antoine
Antoine

Reputation: 1070

Did you did the

$ mkdir myproject
$ cd myproject
$ virtualenv venv

step? (Apparently not)

In any case you should do the pip install Flask after activating the virutualenv. Else it get installed in you base python install.

Also take care, python is case sensitive:

from flask import Flask
app = Flask(__name__)

Upvotes: 1

Related Questions