When you try to install Flask, you might encounter the following error:
$ sudo pip install Flask
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-8.1.2-py2.4.egg/pip/__init__.py", line 208
except PipError as exc:
^
SyntaxError: invalid syntax
$
It's a Python version problem.
You can check with the following code:
try:
print 'a'
except PipError as exc:
print 'b'
With Python 2.4.3, you will get the following error:
$ python -V
Python 2.4.3
$ python try_except.py
File "try_except.py", line 3
except PipError as exc:
^
SyntaxError: invalid syntax
$
With Python 2.6.6, you will get no error as follows:
$ python -V
Python 2.6.6
$
$ python try_except.py
a
$
To install the latest Python, do as follows:
sudo yum install zlib-devel
sudo yum install openssl-devel
cd /home/izeye/programs
wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
tar zxvf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/home/izeye/programs/python
make
make install
cd ..
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
./python/bin/python get-pip.py
./python/bin/pip install Flask
Now you can check Flask is working as follows:
$ ./python/bin/python
Python 2.7.12 (default, Jun 28 2016, 23:29:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>>
No comments:
Post a Comment