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:
pip install package
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.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:
cd ~/example.com/subdomain/dir/
Instead example.com/subdomain/dir
specify the desired path.
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:
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:
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:
temp
by 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.
git clone https://github.com/user/package/
For example, downloading requests will look like this:
git clone git://github.com/psf/requests.git
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
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