0
votes

I'm following the Flask Mega Tutorial from http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world/page/0

I have created the project folder as told, and created the virtualenv using "mkvirtualenv flask" and used "workon flask" to activate it.

After that the tutorial asks to run some commands to install the dependecies of the project running "flask/bin/pip install " but when I try it I get the following error: "bash: flask/bin/pip: No such file or directory". (I believe that's because the folders created for the venv, are not on the folder but on ~/.virtualenvs). So I istalled the dependecies using "(flask)$ pip install "

then I created the files and folders for the project as told, and when I try to run the project I get: bash: ./run.py: flask/bin/python: bad interpreter: No such file or directory

If I run "python run.py" looks like the project is running, but notthing happens, and i get no message saying that the project is running on any port, just this:

  • Restarting with stat
  • Debugger is active!
  • Debugger pin code: 284-703-124

can anyone help me pls? (i'm running on ubuntu 14.04lts)

3
You created your virtual environment in a way not covered by the tutorial. Either you'll need to recreate the environment as instructed in the tutorial or you'll need to adjust all of your commands accordingly (i.e., no flask/bin/). - dirn
Since the new Werkzeug version 0.11 it does not print that status message. The default port is 5000, so just open localhost:5000 in a browser. - Dauros

3 Answers

1
votes

Don't know if this will help but this is how I solved my config issues for The Flask Mega-Tutorial on Mac OS 10.11 El Capitan.

  1. Start from scratch removing all files and folders you've been working with
  2. Follow the Flash install guide on the website http://flask.pocoo.org/docs/latest/installation/

Using the steps in the link above as follows:

$ sudo easy_install virtualenv
$ mkdir myproject
$ cd myproject
$ virtualenv venv
$ . venv/bin/activate
$ pip install Flask

3. Use the $ pip install Flask format for all the items Miguel lists in the $ flask/bin/pip install flask format

$ mkdir app

4. Make the necessary files for the Hello, World! example: app/__init__.py, app/views.py, a run.py
Note: in run.py you will need to change the first line from #!flask/bin/python to #!venv/bin/python
5. Run it

$ chmod a+x run.py
$ ./run.py
0
votes

If you're running "python run.py" and getting this output...

Restarting with stat

Debugger is active!

Debugger pin code: 284-703-124

...then the flask project actually IS running. You've got it working - it just doesn't tell you that in the output above. Open a browser and navigate to http://localhost:5000, though, and you should see the test site up and running.

0
votes

The problem is that in the tutorial, it assumes you have not activated the virtual environment, and you are still in the parent directory where the virtual environment was created.

That's why the commands are all prefixed with flask/bin/pip; flask is the directory where the virtual environment was created.


Once you create a virtual environment you usually follow this up with the activate script. All this script does is changes the paths so commands like python and pip point to the virtual environment's bin folder rather then pointing to the default system location. It also adds a variable to the shell so that programs can detect they are running in a virtual environment, and it adds the name of the virtual environment to the prompt.

If you don't activate the virtual environment, you can still install packages in it by giving the full path to the pip command that is in the virtual environment. Due to the way Python works, it will install packages inside the virtual environment (since that's the first package directory it will find). This is what is happening in the tutorial.

So if you activated the virtual environment, remove flask/bin/ from the instructions and use the commands directly.