1-2 python installation of third-party libraries

python language is famous place is its third-party libraries, officially because of a wealth of third-party libraries, in order to achieve a rich python functions, let's look at how the python is importing third-party libraries.

If you are using from python.org download Python 2> = 2.7.9 or Python 3> = 3.4, or if you are using virtualenv or pyvenv create a virtual environment to work, it has been a pip installed. Just make sure to upgrade PIP . (This is the tool that comes after the installation)

A, pip-line installation

pip python installation is the simplest mode of installing third-party libraries, to use pip online installation, we want to ensure two basic conditions, namely:

1. To install a machine may communicate with the external network

2. Know the name of the third-party libraries

Related documents: https://pip.pypa.io/en/latest/installing.html

With mac computer as an example:

1.1 python modules mounted pip

   To install requests, for example (a third of the requests need to install a library learning web crawlers), the command:

pip install requests

 If errors are reported, showing insufficient permissions, use the command:

sudo pip install requests

1.2 pip tool to uninstall python module

To uninstall requests, for example, the command:

pip uninstall requests

1.3 Use module pip View Installed

To view requests, for example, the command:

pip show --files requests
192:python_tools xxx$ pip show --files requests
Name: requests
Version: 2.18.4
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0

 1.4 pip check which modules need to be updated

command:

pip list --outdated
192:python_tools xxx$ pip list --outdated
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
Cache entry deserialization failed, entry ignored
pip (9.0.1) - Latest: 10.0.1 [wheel]
setuptools (28.8.0) - Latest: 39.1.0 [wheel]
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

 1.5 upgrade module using pip

To upgrade requests, for example, the command:

pip install --upgrade requests

2.1 Based on Python3 install itself using the tools pip
Remember, if you own a Python3 installation, then you do not have to install the tool pip, Python3 installation package comes with pip tools ;
because the Mac comes with Python2, using pip tool Python3 installing the module, must be explicitly specified for the pip Python version, as follows:
to install requests, for example, the command:

pip3 install requests

Is the difference between Python2, pip command instead pip3.

Here require special attention, if you are using third-party libraries pip command to install the default installation directory under python2 to go, when using the import still can not find the path:

Therefore, the installation of a new version of python friend, please use the associated command pip

After the installation is complete

Will prompt succesfully installed the words (please be patient do not quit halfway), then we open the python command line, import the module to try it, if the installation process without error and the normal import process, as shown in the second chart below. So explain this tripartite module installed successfully.

python how to install third-party libraries

Here mention a little extra on how to modify the default python version:

mac installed by default python, the default python version is python2.7. But usually when we could use python application python3, how will we default python environment variable as python3?

1) Open the terminal and type python -V can view the current version of mac python // displayed as python 2.7.xx

2) Upgrade python with a brew, if you have installed manually, ignore this step

brew upgrade python

3) Modify python environment variable to point

Modify the .bash_profile

open -e .bash_profile // open .bash_profile in a text editor
or
vi ~ / .bash_profile
add the following lines

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH


Save changes

source ~/.bash_profile


Modifying .bashrc

The first time you edit the .bashrc file, the file does not exist at this time use

vi ~/.bashrc


Will automatically create and edit the file, add the file

If you do not know your python3 installation path, you can view the path by which python3 command

alias python2='/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
alias python3='/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7'
alias python=python3


Save changes

source ~/.bashrc


At this time, the python can modify the system environment variable to point to python3. Enter python -V terminal to view the current python version.

 

 Second, download the source code package to install

More timely updates to ensure consistency of the module version and pip library source package, but updates are not timely, then, source packages are generally provided updated versions of some. Source package is also available in two formats:

1. tar.gz archive

2. github source address.

For example, you know the source address under git repository:

https://github.com/requests/requests

After the download is complete open the folder you can see:

We can see there is a setup.py file, which is another third-party libraries python installation. 

And execute the installation command:

python setup.py install

Will automatically start the installation file downloaded from third-party libraries, will flash a lot of information, no error, then you do not have control

Wait until the installation is complete, it will directly prompt Finish processing dependence word, which said it had solved the problem of dependence

 

Guess you like

Origin blog.csdn.net/u012717715/article/details/92078257