100% found this document useful (2 votes)
97 views20 pages

Installation Phyton

The document provides instructions for installing Nornir, a Python network automation framework, including: 1) Checking that Python 3.6 or higher is installed and pip is available. 2) Installing Nornir and its dependencies like ruamel.yaml using pip. 3) Verifying the installation by importing Nornir in Python.

Uploaded by

Alberto Velez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
97 views20 pages

Installation Phyton

The document provides instructions for installing Nornir, a Python network automation framework, including: 1) Checking that Python 3.6 or higher is installed and pip is available. 2) Installing Nornir and its dependencies like ruamel.yaml using pip. 3) Verifying the installation by importing Nornir in Python.

Uploaded by

Alberto Velez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Para instalar:

nornir                    3.1.1 requiere Install

Please note that Nornir requires Python 3.6.2 or higher. Install Nornir with pip.

pip install nornir

nornir-netmiko    0.1.1
flask                       2.0.1
requests                2.25.1
ruamel.yaml        0.16.13

INSTALANDO NONIR 3.1.1

https://packaging.python.org/tutorials/installing-packages/

Verificar que se tiene Python 3.8 instalado:

$ pip --version
pip 20.1 from /home/dbarroso/.virtualenvs/nornir/lib/python3.8/site-packages/pip
(python 3.8)

#sudo /usr/local/bin/pip list

Package         Version
--------------- -------
asgiref         3.3.4
configparser    4.0.2
Cython          0.29.24
Django          3.2.4
numpy           1.21.0
pandas          1.2.5
pip             21.1.2
pymysql2        1.3.3
python-dateutil 2.8.1
pytz            2021.1
setuptools      49.2.1
setuptools-scm  3.5.0
six             1.16.0
sqlparse        0.4.1
virtualenv      20.4.7
[soptec@qkclqa01vt ~]$
$ pip install nornir

$ pip install nornir


Collecting nornir
Downloading nornir-3.0.0-py3-none-any.whl (28 kB)
Requirement already satisfied: typing_extensions<4.0,>=3.7 in
/home/dbarroso/.virtualenvs/tmp-nornir/lib/python3.8/site-packages (from nornir)
(3.7.4.2)
Requirement already satisfied: mypy_extensions<0.5.0,>=0.4.1 in
/home/dbarroso/.virtualenvs/tmp-nornir/lib/python3.8/site-packages (from nornir)
(0.4.3)
Collecting ruamel.yaml<0.17,>=0.16
Using cached ruamel.yaml-0.16.10-py2.py3-none-any.whl (111 kB)
Collecting ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and
python_version < "3.9"
Using cached ruamel.yaml.clib-0.2.0-cp38-cp38-manylinux1_x86_64.whl (578 kB)
Installing collected packages: colorama, ruamel.yaml.clib, ruamel.yaml, nornir
Successfully installed nornir-3.0.0 ruamel.yaml-0.16.10 ruamel.yaml.clib-0.2.0
Your output might not be an exact match, the important bit is that last line where
it says that nornir was installed successfully.

Now we can verify that Nornir is installed and that you are able to import the
package from Python.

$ python
>>> from nornir import InitNornir
>>>

Ensure you can run Python from the command line


Before you go any further, make sure you have Python and that the expected
version is available from your command line. You can check this by running:

Unix/macOS
python3 --version

Win

Ensure you can run pip from the command line


Additionally, you’ll need to make sure you have pip available. You can check this by
running:
Unix/macOS

python3 -m pip --version

Windows

If you installed Python from source, with an installer from python.org, or


via Homebrew you should already have pip. If you’re on Linux and installed using your
OS package manager, you may have to install pip separately, see Installing
pip/setuptools/wheel with Linux Package Managers.

If pip isn’t already installed, then first try to bootstrap it from the standard library:

Unix/macOS

python3 -m ensurepip --default-pip

Windows

If that still doesn’t allow you to run python -m pip:

 Securely Download get-pip.py 1

 Run python get-pip.py. 2 This will install or upgrade pip. Additionally, it


will install setuptools and wheel if they’re not installed already.

Warning

Be cautious if you’re using a Python install that’s managed by your operating


system or another package manager. get-pip.py does not coordinate with those
tools, and may leave your system in an inconsistent state. You can
use python get-pip.py --prefix=/usr/local/ to install
in /usr/local which is designed for locally-installed software.
Ensure pip, setuptools, and wheel are up to date
While pip alone is sufficient to install from pre-built binary archives, up to date copies
of the setuptools and wheel projects are useful to ensure you can also install from
source archives:

Unix/macOS

python3 -m pip install --upgrade pip setuptools wheel

Windows

Optionally, create a virtual environment


See section below for details, but here’s the basic venv 3 command to use on a typical
Linux system:

Unix/macOS

python3 -m venv tutorial_env


source tutorial_env/bin/activate

Windows

This will create a new virtual environment in the tutorial_env subdirectory, and


configure the current shell to use it as the default python environment.

Creating Virtual Environments


Python “Virtual Environments” allow Python packages to be installed in an isolated
location for a particular application, rather than being installed globally. If you are
looking to safely install global command line tools, see Installing stand alone command
line tools.

Imagine you have an application that needs version 1 of LibFoo, but another application
requires version 2. How can you use both these applications? If you install everything
into /usr/lib/python3.6/site-packages (or whatever your platform’s standard location is),
it’s easy to end up in a situation where you unintentionally upgrade an application that
shouldn’t be upgraded.
Or more generally, what if you want to install an application and leave it be? If an
application works, any change in its libraries or the versions of those libraries can break
the application.

Also, what if you can’t install packages into the global site-packages directory? For
instance, on a shared host.

In all these cases, virtual environments can help you. They have their own installation
directories and they don’t share libraries with other virtual environments.

Currently, there are two common tools for creating Python virtual environments:

 venv is available by default in Python 3.3 and later, and


installs pip and setuptools into created virtual environments in Python 3.4 and
later.
 virtualenv needs to be installed separately, but supports Python 2.7+ and Python
3.3+, and pip, setuptools and wheel are always installed into created virtual
environments by default (regardless of Python version).

The basic usage is like so:

Using venv:

Unix/macOS

python3 -m venv <DIR>


source <DIR>/bin/activate

Windows

Using virtualenv:

Unix/macOS

python3 -m virtualenv <DIR>


source <DIR>/bin/activate

Windows
For more information, see the venv docs or the virtualenv docs.

The use of source under Unix shells ensures that the virtual environment’s variables are
set within the current shell, and not in a subprocess (which then disappears, having no
useful effect).

In both of the above cases, Windows users should _not_ use the source command, but
should rather run the activate script directly from the command shell like so:

<DIR>\Scripts\activate

Managing multiple virtual environments directly can become tedious, so


the dependency management tutorial introduces a higher level tool, Pipenv, that
automatically manages a separate virtual environment for each project and application
that you work on.

Use pip for Installing


pip is the recommended installer. Below, we’ll cover the most common usage scenarios.
For more detail, see the pip docs, which includes a complete Reference Guide.

Installing from PyPI


The most common usage of pip is to install from the Python Package Index using
a requirement specifier. Generally speaking, a requirement specifier is composed of a
project name followed by an optional version specifier. PEP 440 contains a full
specification of the currently supported specifiers. Below are some examples.

To install the latest version of “SomeProject”:

Unix/macOS

python3 -m pip install "SomeProject"

Windows

To install a specific version:


Unix/macOS

python3 -m pip install "SomeProject==1.4"

Windows

To install greater than or equal to one version and less than another:

Unix/macOS

python3 -m pip install "SomeProject>=1,<2"

Windows

To install a version that’s “compatible” with a certain version: 4

Unix/macOS

python3 -m pip install "SomeProject~=1.4.2"

Windows

In this case, this means to install any version “==1.4.*” version that’s also “>=1.4.2”.

Source Distributions vs Wheels


pip can install from either Source Distributions (sdist) or Wheels, but if both are present
on PyPI, pip will prefer a compatible wheel. You can override pip`s default behavior by
e.g. using its –no-binary option.

Wheels are a pre-built distribution format that provides faster installation compared


to Source Distributions (sdist), especially when a project contains compiled extensions.

If pip does not find a wheel to install, it will locally build a wheel and cache it for future
installs, instead of rebuilding the source distribution in the future.
Upgrading packages
Upgrade an already installed SomeProject to the latest from PyPI.

Unix/macOS

python3 -m pip install --upgrade SomeProject

Windows

Installing to the User Site


To install packages that are isolated to the current user, use the --user flag:

Unix/macOS

python3 -m pip install --user SomeProject

Windows

For more information see the User Installs section from the pip docs.

Note that the --user flag has no effect when inside a virtual environment - all
installation commands will affect the virtual environment.

If SomeProject defines any command-line scripts or console entry points, --


user will cause them to be installed inside the user base’s binary directory, which may
or may not already be present in your shell’s PATH. (Starting in version 10, pip displays
a warning when installing any scripts to a directory outside PATH.) If the scripts are not
available in your shell after installation, you’ll need to add the directory to your PATH:

 On Linux and macOS you can find the user base binary directory by
running python -m site --user-base and adding bin to the end. For
example, this will typically print ~/.local (with ~ expanded to the absolute
path to your home directory) so you’ll need to add ~/.local/bin to
your PATH. You can set your PATH permanently by modifying ~/.profile.
 On Windows you can find the user base binary directory by running py -
m site --user-site and replacing site-packages with Scripts. For
example, this could return C:\Users\Username\AppData\Roaming\
Python36\site-packages so you would need to set your PATH to
include C:\Users\Username\AppData\Roaming\Python36\Scripts.
You can set your user PATH permanently in the Control Panel. You may need to
log out for the PATH changes to take effect.
Requirements files
Install a list of requirements specified in a Requirements File.

Unix/macOS

python3 -m pip install -r requirements.txt

Windows

Installing from VCS


Install a project from VCS in “editable” mode. For a full breakdown of the syntax, see
pip’s section on VCS Support.

Unix/macOS

python3 -m pip install -e


git+https://git.repo/some_pkg.git#egg=SomeProject #
from git
python3 -m pip install -e
hg+https://hg.repo/some_pkg#egg=SomeProject #
from mercurial
python3 -m pip install -e
svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject #
from svn
python3 -m pip install -e
git+https://git.repo/some_pkg.git@feature#egg=SomeProject #
from a branch

Windows

Installing from other Indexes


Install from an alternate index
Unix/macOS

python3 -m pip install --index-url


http://my.package.repo/simple/ SomeProject

Windows

Search an additional index during install, in addition to PyPI

Unix/macOS

python3 -m pip install --extra-index-url


http://my.package.repo/simple SomeProject

Windows

Installing from a local src tree


Installing from local src in Development Mode, i.e. in such a way that the project
appears to be installed, but yet is still editable from the src tree.

Unix/macOS

python3 -m pip install -e <path>

Windows

You can also install normally from src

Unix/macOS

python3 -m pip install <path>

Windows
Installing from local archives
Install a particular source archive file.

Unix/macOS

python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz

Windows

Install from a local directory containing archives (and don’t check PyPI)

Unix/macOS

python3 -m pip install --no-index --find-


links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/
SomeProject
python3 -m pip install --no-index --find-links=relative/dir/
SomeProject

Windows

Installing from other sources


To install from other data sources (for example Amazon S3 storage) you can create a
helper application that presents the data in a PEP 503 compliant index format, and use
the --extra-index-url flag to direct pip to use that index.

./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777
SomeProject

Installing Prereleases
Find pre-release and development versions, in addition to stable versions. By default,
pip only finds stable versions.
Unix/macOS

python3 -m pip install --pre SomeProject

Windows

Installing Setuptools “Extras”


Install setuptools extras.

Unix/macOS

python3 -m pip install SomePackage[PDF]


python3 -m pip install SomePackage[PDF]==3.0
python3 -m pip install -e .[PDF]==3.0 # editable project in
current directory

Windows

“Secure” in this context means using a modern browser or a tool like curl that


verifies SSL certificates when downloading from https URLs.

Depending on your platform, this may require root or Administrator


access. pip is currently considering changing this by making user installs the
default behavior.

Beginning with Python 3.4, venv (a stdlib alternative to virtualenv) will create


virtualenv environments with pip pre-installed, thereby making it an equal
alternative to virtualenv.

The compatible release specifier was accepted in PEP 440 and support was
released in setuptools v8.0 and pip v6.0
INSTALANDO FLASK 2.0.1

Project description
Flask is a lightweight WSGI web application framework. It is designed to make
getting started quick and easy, with the ability to scale up to complex
applications. It began as a simple wrapper around Werkzeug and Jinja and has
become one of the most popular Python web application frameworks.

Flask offers suggestions, but doesn’t enforce any dependencies or project


layout. It is up to the developer to choose the tools and libraries they want to
use. There are many extensions provided by the community that make adding
new functionality easy.

Installing

Install and update using pip:

$ pip install -U Flask

A Simple Example

# save this as app.py

from flask import Flask

app = Flask(__name__)

@app.route("/")

def hello():

return "Hello, World!"


$ flask run

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Contributing

For guidance on setting up a development environment and how to make a


contribution to Flask, see the contributing guidelines.

Donate

The Pallets organization develops and supports Flask and the libraries it uses.
In order to grow the community of contributors and users, and allow the
maintainers to devote more time to the projects, please donate today.

Links

 Documentation: https://flask.palletsprojects.com/

INSTALANDO REQUESTS 2.25.1

Project description
Requests

Requests is a simple, yet elegant, HTTP library.

>>> import requests

>>> r = requests.get('https://api.github.com/user', auth=('user',


'pass'))

>>> r.status_code

200
>>> r.headers['content-type']

'application/json; charset=utf8'

>>> r.encoding

'utf-8'

>>> r.text

'{"type":"User"...'

>>> r.json()

{'disk_usage': 368627, 'private_gists': 484, ...}

Requests allows you to send HTTP/1.1 requests extremely easily. There’s no


need to manually add query strings to your URLs, or to form-encode
your  PUT  &  POST  data — but nowadays, just use the  json  method!

Requests is one of the most downloaded Python package today, pulling in


around  14M downloads / week — according to GitHub, Requests is
currently depended upon by  500,000+  repositories. You may certainly put your
trust in this code.

   

Installing Requests and Supported Versions

Requests is available on PyPI:

$ python -m pip install requests

Requests officially supports Python 2.7 & 3.6+.

Supported Features & Best–Practices

Requests is ready for the demands of building robust and reliable HTTP–
speaking applications, for the needs of today.
 Keep-Alive & Connection Pooling
 International Domains and URLs
 Sessions with Cookie Persistence
 Browser-style TLS/SSL Verification
 Basic & Digest Authentication
 Familiar  dict –like Cookies
 Automatic Content Decompression and Decoding
 Multi-part File Uploads
 SOCKS Proxy Support
 Connection Timeouts
 Streaming Downloads
 Automatic honoring of  .netrc
 Chunked HTTP Requests

INSTALANDO ruamel.yaml 0.16.13

Project description
ruamel.yaml

ruamel.yaml  is a YAML 1.2 loader/dumper package for Python.


version: 0.16.13

updated: 2021-03-05

documentation: http://yaml.readthedocs.io

repository: https://sourceforge.net/projects/ruamel-yaml/

pypi: https://pypi.org/project/ruamel.yaml/

The 0.16.13 release is the last that will tested to be working on Python 2.7. The
0.17 series will still be tested on Python 3.5, but the 0.18 will not. The 0.17
series will also stop support for the old PyYAML functions, so a `YAML()`
instance will need to be created.

Please adjust your dependencies accordingly if necessary.

Starting with version 0.15.0 the way YAML files are loaded and dumped is
changing. See the API doc for details. Currently existing functionality will throw
a warning before being changed/removed. For production systems you
should pin the version being used with ``ruamel.yaml<=0.15``. There might
be bug fixes in the 0.14 series, but new functionality is likely only to be available
via the new API.

If your package uses  ruamel.yaml  and is not listed on PyPI, drop me an email,
preferably with some information on how you use the package (or a link to
bitbucket/github) and I’ll keep you informed when the status of the API is stable
enough to make the transition.

 Overview
 Installing
 Basic Usage
 Details
 Examples
 API
 Differences with PyYAML

INSTALANDO SETUPTOOLS>=20.6.8

Instalando PIP

https://access.redhat.com/solutions/1519803

Installing
Make sure you have a recent version of  pip  and  setuptools  installed. The later
needs environment marker support ( setuptools>=20.6.8 ) and that is e.g. bundled
with Python 3.4.6 but not with 3.4.4. It is probably best to do:

pip install -U pip setuptools wheel


in your environment ( virtualenv , (Docker) container, etc) before
installing  ruamel.yaml .

ruamel.yaml  itself should be installed from PyPI using:

pip install ruamel.yaml


If you want to process jinja2/YAML templates (which are not valid YAML with
the default jinja2 markers), do  pip install ruamel.yaml[jinja2]  (you might need to
quote the last argument because of the  [] )

There also is a commandline utility  yaml  available after installing:

pip install ruamel.yaml.cmd


that allows for round-trip testing/re-indenting and conversion of YAML files
(JSON,INI,HTML tables)

Optional requirements
If you have the the header files for your Python executables installed then you
can use the (non-roundtrip), but faster, C loader and emitter.

On Debian systems you should use:

sudo apt-get install python3-dev


you can leave out  python3-dev  if you don’t use python3

For CentOS (7) based systems you should do:

sudo yum install python-devel

Verify the following commands:

Raw

$ rpm -qf /bin/scl


scl-utils-20130529-18.el7_4.x86_64

$ scl -l
python27

$ scl enable python27 bash

$which pip
/opt/rh/python27/root/usr/bin/pip

$ pip -V
pip 8.1.2 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python
2.7)

[root@qgslsasl04vt ~]# python3 --version


Python 3.6.8
[root@qgslsasl04vt ~]# python3 -m pip --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
[root@qgslsasl04vt ~]# more /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)
[root@qgslsasl04vt ~]# rpm -qa|grep zlib
zlib-1.2.7-18.el7.x86_64
[root@qgslsasl04vt ~]# rpm -qa|grep libffi
libffi-3.0.13-18.el7.x86_64
[root@qgslsasl04vt ~]# rpm -qa|grep libffi-devel
[root@qgslsasl04vt ~]# pwd

Instalando python

Les paso las instrucciones para instalar python3

---- se requieren los siguientes rpms antes de instalar python3

libffi-3.0.13-18.el7.x86_64

libffi-devel-3.0.13-18.el7.x86_64

zlib-devel-1.2.7-17.el7.x86_64

zlib-1.2.7-17.el7.x86_64

bajar paquete de pyton3

tar -xvJf Python-3.8.1.tar.xz

----Python3

./configure

make

make install

---------

---- se descomprie cada modulo y en el directorio generado

---- Instalar modulos de python con : python3 setup.py install en ese orden

-- setuptools-45.2.0

-- setuptools_scm-3.5.0
-- pip-21.1.2

-- configparser-4.0.2.tar

-- Cython-0.29.24.tar

-- six-1.16.0

-- virtualenv-20.4.7

-- asgiref-3.3.4.tar

-- Django-3.2.4.tar

-- numpy-1.21.0.zip

-- pytz-2021.1.tar

-- pandas-1.2.5.tar

-- python-dateutil-2.8.1.tar

-- sqlparse-0.4.1.tar

-- pymysql2-1.3.3.tar.gz

-- mysqlclient-2.0.3.tar

You might also like