1

I just download a web application which written using Python. Im completely new to Python. After i do some research, below is what i have done

1) Install Python 2.7

2) Install pip (How do I install pip on Windows?)

When i try to run the python file by using this command

Python PATH/test.py

It show

Traceback (most recent call last):
File "PATH\test.py", line 1, in <module>
from flask import Blueprint, flash, request, render_template

Python Code:

from flask import Blueprint, flash, request, render_template
from steam import vdf
import json

vdfjson = Blueprint("vdfjson", __name__, template_folder="templates")


@vdfjson.route('/', methods=["GET", "POST"])
def index():
response = None
format = "json"
if request.method == "POST":
    format = request.form["format"]
    data = request.form["data"]

    try:
        if format == "vdf":
            response = json.dumps(
                vdf.loads(data),
                indent=4
            )

        elif format == "json":
            _response = json.loads(data)
            response = vdf.dumps(_response).decode("utf-16")

    except ValueError:
        flash("ValueError:  Your {} may not be valid.".format(format), "danger")
        response = "{}" if format == "json" else ""

return render_template("vdfjson.html", response=response, format=format, title="vdfjson")

*It is a web application, so im not sure whether i follow the right instruction or not.

I try to install flask

pip install flask

and i get below error

C:\Python27\Scripts>pip install Flask
Downloading/unpacking Flask
Downloading Flask-0.10.1.tar.gz (544kB): 544kB downloaded
Running setup.py egg_info for package Flask
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'include_package_data'
  warnings.warn(msg)
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'zip_safe'
  warnings.warn(msg)
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'install_requires'
  warnings.warn(msg)
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'test_suite'
  warnings.warn(msg)
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: -c --help [cmd1 cmd2 ...]
   or: -c --help-commands
   or: -c cmd --help

error: invalid command 'egg_info'
Complete output from command python setup.py egg_info:
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'include_package_data'

warnings.warn(msg)

C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option:
'zip_safe'

warnings.warn(msg)

C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option:
'install_requires'

warnings.warn(msg)

C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option:
'test_suite'

warnings.warn(msg)

usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]

or: -c --help [cmd1 cmd2 ...]

or: -c --help-commands

or: -c cmd --help



error: invalid command 'egg_info'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in c:\users\sam\appdat
a\local\temp\pip_build_SAM\Flask
Storing complete log in C:\Users\SAM\pip\pip.log

C:\Python27\Scripts>

After that i execute again

Python PATH/test.py

it did not show any error but do nothing.

3
  • Do you have Blueprint installed? Try running pip install blueprint. Commented Oct 11, 2013 at 10:43
  • Blueprint is a Flask module, there is no need to install it seperatly. Commented Oct 11, 2013 at 11:05
  • Also, I didn't found module called steam. Be sure, that you have it. Commented Oct 11, 2013 at 11:27

5 Answers 5

1

It is not a complete flask application. You need to make Flask instance and then register your blueprint in it. Try to run the code below:

from flask import Blueprint, Flask, flash, request, render_template
from steam import vdf
import json
app = Flask(__name__)


vdfjson = Blueprint("vdfjson", __name__, template_folder="templates")
app.register_blueprint(vdfjson)


@vdfjson.route('/', methods=["GET", "POST"])
def index():
    response = None
    format = "json"
    if request.method == "POST":
        format = request.form["format"]
        data = request.form["data"]

        try:
            if format == "vdf":
                response = json.dumps(
                    vdf.loads(data),
                    indent=4
                )

            elif format == "json":
                _response = json.loads(data)
                response = vdf.dumps(_response).decode("utf-16")

        except ValueError:
            flash("ValueError:  Your {} may not be valid.".format(format), "danger")
            response = "{}" if format == "json" else ""

        return render_template("vdfjson.html", response=response, format=format, title="vdfjson")

if __name__ == '__main__':
    app.run()
Sign up to request clarification or add additional context in comments.

4 Comments

I get this error: Traceback (most recent call last): File "PATH\test2.py", line 1, in <module> from flask import Blueprint, Flask, flash, request, render_template ImportError: No module named flask
That means, you don't have flask, so you have to install it.
I get some error during installation of flask. Please refer to the updated post.
Ok. Right now. After i execute "Python PATH/test.py" it did not show any error but do nothing. Is that normal?
1

You'll need to install flask (and possibly some other libraries). Start with flask and see what errors you get after.

pip install flask

Often there's a requirements.txt file with the project that has the list of dependencies. You can then just run:

pip install -r ./path_to/requirements.txt

Which will install them all for you. Once you're more comfortable look into virtualenv which will allow you to create isolated environments for installing your libraries on a per project basis.

5 Comments

I get some error during installation of flask. Please refer to the updated post.
Looks like you have some issue with the setup tools. Apparently you need to run 'pip install --upgrade setuptools' (then try again). stackoverflow.com/questions/11425106/…
Thanks. I re run using "Python PATH/test.py" this time no more error but nothing show.
Sounds like now you want to try @Alexander Zhukov's solution above. The test.py that you showed us is for a Blueprint - it's like a submodule of an application that expects to be included in something bigger. You really need the application itself. I have no idea what the project is but I would have thought there would be a main application file with it somewhere.
Just to add - once it's running it should look the terminal has frozen and you'll be able to access it in your web browser by going to localhost:5000
1

The author has update the latest version of the original source source. So it work right now. Case closed. Thanks.

Comments

0

You successfully run your test.py,
however libraries

from flask import Blueprint, flash, request, render_template

you try to import is not in PYTHONPATH

1 Comment

Means that the library file is missing? Is there any way to check the path of my libraries?
0

This worked for me:

pip install -u setuptools

pip install flask

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.