Reputation: 397
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.
Upvotes: 1
Views: 6230
Reputation: 10249
This worked for me:
pip install -u setuptools
pip install flask
Upvotes: 0
Reputation: 397
The author has update the latest version of the original source source. So it work right now. Case closed. Thanks.
Upvotes: 1
Reputation: 4006
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.
Upvotes: 1
Reputation: 4547
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()
Upvotes: 1
Reputation: 7640
You successfully run your test.py
,
however libraries
from flask import Blueprint, flash, request, render_template
you try to import is not in PYTHONPATH
Upvotes: 0