python and pip
pip is used to install packages/modules in python. pypi is the default software repository for python packages. python started packaging pip with python 3.4. For older versions, you might have to install it. You might have multiple versions of python and pip in your machine.
Different versions of pip
node1# pip --version pip 19.0.3 from /usr/lib/python2.7/site-packages/pip (python 2.7) node1# pip3.6 --version pip 8.1.2 from /usr/lib/python3.6/site-packages (python 3.6)
Basic pip commands
pip –version
python -m pip install <packagename>
python3 -m pip install <packagename>
python -m pip install –upgrade <packagename> ## Note: here you don’t have to say pip2 or pip3
python3 -m pip install –upgrade <packagename>## Note: here you don’t have to say pip2 or pip3
pip list ## list installed packages
pip show <module>
pip uninstall <packagename>
How to list all available modules available to your python environment?
help(“modules”) command will give you list of all modules you can use.
node1 # python3 Python 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> help ("modules") ... ...
How to install flask in CentOS 7.5?
# python3 -m pip install flask
Collecting flask
Downloading https://files.pythonhosted.org/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
100% |████████████████████████████████| 102kB 2.1MB/s
Collecting click>=5.1 (from flask)
Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
100% |████████████████████████████████| 81kB 3.1MB/s
Collecting itsdangerous>=0.24 (from flask)
Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from flask)
Downloading https://files.pythonhosted.org/packages/ce/42/3aeda98f96e85fd26180534d36570e4d18108d62ae36f87694b476b83d6f/Werkzeug-0.16.0-py2.py3-none-any.whl (327kB)
100% |████████████████████████████████| 327kB 1.8MB/s
Collecting Jinja2>=2.10.1 (from flask)
Downloading https://files.pythonhosted.org/packages/65/e0/eb35e762802015cab1ccee04e8a277b03f1d8e53da3ec3106882ec42558b/Jinja2-2.10.3-py2.py3-none-any.whl (125kB)
100% |████████████████████████████████| 133kB 2.0MB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->flask)
Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, flask
Successfully installed Jinja2 MarkupSafe Werkzeug click flask itsdangerous
You are using pip version 8.1.2, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Above command will install flask in /usr/local/lib64/python3.6/site-packages/
Now let’s try to import flask module
node1 #python3 Python 3.6.8 (default, Apr 25 2019, 21:02:35) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import flask >>>
it worked as we installed pip using python3.
node1 #python Python 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import flask Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named flask >>>
above didn’t work as python2.7.5 is unaware of the flask module path!
How to get details of a module?
pip show <module>
node1 # pip3 show flask
---
Metadata-Version: 2.1
Name: Flask
Version: 1.1.1
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
Installer: pip
License: BSD-3-Clause
Location: /usr/local/lib64/python3.6/site-packages
Requires: Werkzeug, click, itsdangerous, Jinja2
Classifiers:
Development Status :: 5 - Production/Stable
Environment :: Web Environment
Framework :: Flask
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Topic :: Software Development :: Libraries :: Application Frameworks
Topic :: Software Development :: Libraries :: Python Modules
Entry-points:
[console_scripts]
flask = flask.cli:main
As you can see there is critical information: It has list of supported python versions, Required packages, OS dependencies etc.
You must be logged in to post a comment.
+ There are no comments
Add yours