We use cookies
We use cookies to optimize our website. By continuing to browse the site, you agree to our use of cookies.
New design
Control panel
  • Русский
  • Українська
  • English
  • UAH
  • USD
  • RUB
  • EUR
  • 0-800-307-307 Hotline
  • +38 (044) 392-74-33 Kiev
  • +38 (057) 728-39-00 Kharkiv
  • +38 (056) 794-38-31 Dnipro
  • +38 (032) 229-58-93 Lviv
  • +38 (048) 738-57-70 Odessa
  • +38(093) 170-15-42  Life
  • +38 (067) 400-88-44 Kievstar
  • +1(888)393-24-51  USA, Toll free
  • +44(131)507-01-14  Great Britain
  • +7 (499) 348-28-61 Moscow

2.23.1.2. Installing Python Libraries

To install libraries in Python, you can use either locally linking library files to scripts or installing packages within the Python virtual environment.

The installation process for libraries depends on the version you need and the method chosen:

To install packages using pip, do the following:

  1. Install the required packages with the command:
    pip install package
    • Instead pip substitute the appropriate pip version notation:
      • pip or pip3.6 - for Python version 3.6.
      • pip3.3 - for Python version 3.3.
      • pip2 - for Python version 2.7.
    • Instead package specify the name of the package you want to install. For example, the install command bcrypt for python 3.6 it will look like this:
      pip install bcrypt

A virtual environment in Python allows you to create a separate environment that has its own dependencies and packages. You can create virtual environments only in versions of Python 3 and higher, since the standard module is used venv... This is not possible for Python version 2. More details on working with the virtual environment are described in documentation.

To create a virtual environment, do the following:

  1. Change to the directory where you want to place the virtual environment using the command:
    cd ~/example.com/subdomain/dir/ 

    Instead example.com/subdomain/dir specify the desired path.

  2. Run the command to create a virtual environment in the current working directory:
    pythonX -m venv example

    Instead X specify the version of Python you want (for example 3 or 3.6), instead of example Is the name for the virtual environment.

After completing the specified actions, a directory with the name of the virtual environment will be created, in which all subsequent actions will be performed.

To activate and enter the virtual environment, do the following:

  1. Run the activation command:
    source /path/to/env/bin/activate

    Instead /path/to/env specify the path to the directory where the virtual environment was created.

If everything is done correctly, then the name of the virtual environment will be displayed at the command line prompt, for example (example) -bash-4.2$.

To turn off the virtual environment, run the command:

deactivate

To install packages using pip, do the following:

  1. Create and activate virtual environment for Python version 3.6.
  2. Install the required packages with the command:
    pip install package

    Instead package specify the name of the package you want to install. For example, the install command bcrypt will look like this:

    pip install bcrypt

To install packages manually, do the following:

  1. Create and activate virtual environment for Python of the required version.
  2. Create a temporary directory and change to it. For example, in the virtual environment directory, create a directory tempby running the commands:
    mkdir /path/to/env/temp
    cd !$

    Instead /path/to/env specify the path to the directory where the virtual environment was created.

  3. For further installation, the required package must be downloaded to this directory. The difference in downloading is the download method used. Please note, be sure to download only source-versions of packages. Download methods:
    • If you are using GitHub, you can download the package using the command:
      git clone https://github.com/user/package/

      For example, downloading requests will look like this:

      git clone git://github.com/psf/requests.git
    • If you are using a third-party repository, then to download the archive you need to run the command:
      wget https://example.com/package.zip

      After downloading, you will need to unpack the archive using the zip or tar utilities, or using filemanager... For example, downloading and unpacking requests will look like this:

      wget https://github.com/psf/requests/archive/master.zip
      unzip master.zip
    • You can manually download the required package files as an archive and upload them using filemanager or any FTPclient, then unpack archive.
  4. After downloading all the package files, you need to install it by running the command:
    cd package
    python setup.py install

    Instead package specify the name of the directory where the files of the required package are located. For example, setting requests looks like that:

    cd requests-master
    python setup.py install