Python Installation Module Method summary

Source: Internet
Author: User

Method One:

Original address:

http://blog.csdn.net/cighao/article/details/47860041

Under Windows System, you only need to enter the command PIP install requests to install.

Under the Linux system, just enter the command sudo pip install requests to install.

Note: For the installation of Python third-party libraries, it is best to use easy_install less, because Easy_install can only install cannot uninstall, if you want to uninstall the directory that needs to go to Python under the folder of the Lib to manually delete the corresponding module content. So it is recommended to use PIP installation, installation, with the PIP install + module name command to install, uninstall, with the PIP uninstall + module name command to delete.

Since the use of PIP or Easy_install installation in the country often wall, the following emphasis on another installation method.

1. Download requests

Open this URL, http://www.lfd.uci.edu/~gohlke/pythonlibs on this site has a lot of Python third-party library files, we press Ctrl+f search is easy to find requests. Such as

Click on the. whl file and download it.

2. After downloading the. whl file, rename the file, change the suffix name from. WHL to. zip, then unzip the file, we can get two folders, such as,

We copy the first folder, the requests folder, to the directory under the Python installation.

3. Here, requests has been installed, we can enter the import requests command to try whether the installation is successful,

As shown, import requests no error, indicating that requests has been successfully installed.

#######################################################################################

##############################################################################

Method Two:

Original address: http://www.th7.cn/Program/Python/201606/880093.shtml

Python is an elegant language, concise syntax, powerful features. Of course, the rich third-party library, more able to accelerate the development. So the question is, how do you install these third-party libraries (packages)?

There are few ways to install third-party libraries. Here are some tips.

SOURCE Installation
Many third-party libraries are open source, and almost all can be found on GitHub or PyPI. Find the source format is probably the zip, tar.zip, tar.bz2 format of the compressed package. Unpack the packages and go to the Unpacked folder, and you'll usually see a setup.py file. Open the command line and go to the folder. Run




Python setup.py Install


This command, you can install the third library into the system, that is, your Python path, Windows is probably in the c:python2.7libsite-packages.
Linux will be in/usr/local/lib/python2.7/dist-packages.
Mac should be in/library/python/2.7/site-packages. If installed in a virtulenv environment, the package is installed in the site-packages/directory under the virtual environment that was created. To uninstall these libraries is also very simple, into the site-packages, directly delete the library file is OK. Of course, these installations may be a little cumbersome, need to download, unzip, and then run the installation, uninstall is not very convenient. Is there a tool that can help manage these libraries outside?

Package Manager (PIP and Easy_install)
Many programming languages now come with package managers, such as the Gem,nodejs npm of Ruby. Python is certainly no exception, with the famous Pip and Easy_install.

The pypi mentioned above is the source of some Python third libraries, using PIP or Easy_install to install the module, search for the source, and then download the installation automatically. For example we need to install the Flask framework specific commands as follows:




Pip Install flask


Or




Easy_install Flask


Simple, a simple command is done. Uninstall is also very convenient, for example we need to uninstall flask




Pip Uninstall flask


View the installed packages, including the system's own and manually installed




PIP List


You can also search for packages




Pip Search Flask


You can also redirect the libraries that the output project uses.




Pip Freeze > Requirements.txt


This will redirect the third-party libraries in that environment to the Requirements.txt file, and if you give others a dependency on the project, you only need to run:




Pip Install-r requirements.txt


It's very convenient. Of course, sometimes, our network is not so smooth, Pip is installed online, can you leave floss? Of course, the first step in Pip install is to find the package on PyPI and download it locally. If the network is not good, you can first build a local warehouse, the commonly used packages offline download. For example, you can download flask source code




Pip Intall flask-master.zip


It can also be installed.

Virtual Environment Related installation
Of course, the above mentioned, in fact, is also very common, but also not what skills. Here are some tips for understanding the principles and solving unconventional problems.

Using Python, we would like to use virtualenv to build a virtual environment, such as building a venv virtual environment. We just need the source to go in and we can use PIP to install it. However, sometimes, even in a virtual environment, using the sudo prefix (Windows ignore), the installed library is not in the virtual environment, but is installed in the system under the Site-package directory.

Windows users may be happy and don't need to be aware of this issue. Windows, of course, also has its own problems. Installing Python on Windows is generally a compiled binary package exe executable file. Typically there are 32-bit and 64-bit python. For third-party libraries, there would not be much difference between 32 and 64. But for some C-written Python libraries, such as Mysqldb,pil, pillow, you'll find that using PIP or Easy_install will cause an error:




Fixing Python error:unable to find Vcvarsall.bat


The reason is probably missing some C compiler stuff on Windows. The source code needs to compile to install, at this time Windows is very bitter force. Of course, there are some good-hearted people, help you to compile some of the commonly used libraries into EXE executable files, put to this site. You just need to look for the version, download one-click Install.

However, there is a problem, download EXE file, run the installation, this library is installed in the system's Site-package directory, if I set up a venv virtual environment in Windows, so installation is not a break?

Don't worry, the real trick in this article is to solve the problem. Let's install the 64-bit mysqldb. First download the Mysql?python?1.2.5.win?amd64?py2.7.exe on Windows and use the command line to enter the virtual environment venv. And then run




Easy_install Mysql?python?1.2.5.win?amd64?py2.7.exe


Perfect solution, in the VENV virtual environment, the MYSQLDB Library was installed under VENV.

With the top three ways, the third-party library installation covers almost all of Python's platforms. However, although Python is a cross-platform, development environment, or as much as possible using Linux or MacOS, these two systems have better tools and save a lot of puzzling problems.

Python Installation Module Method summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.