Python Configuration third-party library Theano the road of twists and turns

Source: Internet
Author: User
Tags theano

Theano is a third-party library of deep learning in Python, and today some classmates asked me how to configure it. OK, since there is demand, I spent half a day researching it and completing the configuration under Windows 32-bit and 64-bit systems. Here in the process of configuration I took a few detours, in this article I will be in the configuration process encountered problems, errors, the solution is a complete list for everyone to refer to, and list the direct and concise configuration method.

First, the basic situation

Theano is a relatively complex library in Python, and here is a basic explanation of the current configuration requirements.

1, Python Configuration third-party library basic method

Python configures third-party libraries mainly in the following ways:

(1) PIP automatic installation

Pip is the preferred method for Python to install third-party libraries, which is quick and easy, and the system automatically analyzes the installation requirements and downloads the appropriate library files from pipy. The PIP tool is installed by default when the Python compiler is installed, and the PIP tool installs the third-party library simply by entering the PIP install library name in the command Prompt window.

You first need to configure the relevant environment variables when using the PIP tool. Suppose we put Python in the C packing directory:

You need to add the directory and the path to the Scripts folder under the directory to the environment variable:

Next we open a command prompt window, first need to make the PIP version more line, update to the latest version can be used, update command "Pip install--upgrade pip":

Once the update is complete, you can use the PIP tool to install the third-party library. Here is a question to note that Python must be installed in the C drive to complete the version update, before the installation of the D drive, during the version update process will always show the file movement errors, this bug has not been resolved, fortunately, Python itself is not large, and relatively concise, It's on the C drive for the moment.

Next you can use PIP for automatic installation, very concise, direct "pip Install Library name" can:

Here we have installed the Theano, so Pip will give a message, otherwise it will be installed automatically.

(2) PIP manual Installation

The so-called PIP manual installation means that we manually download the installation files for third-party libraries and then install them using PIP. Here are the third library installation files: third-party libraries, download the attention to version matching.

Note that the installation files here are in WHL format, not exe or MSI format, it means that the downloaded installation files can only be installed with the PIP tool, the direct double-click is not feasible.

Suppose we use PIP to manually install the SciPy module. Download the installation file for scipy in the address that you just had, select the Win32, CP34 (Python3.4) version of the installation file:

After the download is complete, for convenience, put the file in the C packing directory, and then at the command prompt interface into the C-drive folder, using the PIP command to install:

This is because the NumPy module has been installed before and the PIP will give you a hint. If the relevant module is not previously installed, Pip will install it here automatically. However, it is important to note that when you use PIP for manual installation, you must first enter the directory where the installation files are located, or Pip will not be able to locate the installation source.

(3) Install with EXE file

For some commonly used third-party libraries, the following address may be found in the corresponding EXE version of the installation files: EXE installation file address, if you can search the site of the relevant EXE version of the installation files, download down directly double-click installation can, of course, also need to pay attention to the issue of version matching, And there seems to be no 64-bit version of the installation file.

2. Installation Environment requirements

Before installing the Theano library, you need support for the following extension libraries: NumPy (including Blas,atlas, etc.), scipy, Libpython, g++ support (via MinGW installation), where g++ needs to differentiate between 32-bit and 64-bit. My computer is a win7,64 bit, but my python is 32 bits (64-bit Windows is capable of installing 32-bit python). This is because our Python is 32 bits, so all the modules installed below are 32-bit versions.

Second, start the installation

1. Install third-party libraries

Install NumPy first. After testing the above three methods can install the NumPy module, but there must be a second type, that is, manually download the NumPy module to install with PIP. The reason is that the other two methods after installing the NumPy module, but also need to manually install Blas, Atlas, and so on, and these two modules are required to compile to install, very cumbersome, and the download of the numpy seems to encapsulate these cumbersome modules, so can save a lot of effort.

After installation, continue to install the SciPy module, here we also recommend the use of the second method of manual installation, convenient and fast, not subject to speed constraints. Automatic installation with PIP often fails to download anything.

Then install the Libpython module, ibid.

The installation process of these three modules is identical, here is a brief summary: in Python installation of third-party modules recommended manual installation, convenient and quick. Using PIP to install automatically will be limited by a variety of factors such as firewall, network speed, and low success rate of installation. Of course, if you can't find the corresponding WHL installation files (such as the Nose module), you can only use PIP for automatic online installation. It is not recommended to go to SourceForge to find EXE version, an EXE version of the installation files are not comprehensive, second, EXE version of the installation of the library and Pip installed library is not exactly the same, a long time may lead to unknown compatibility issues, third, EXE version of the installation files are not 64-bit.

After installing the above extension libraries, you can install the Theano library. This must be installed using PIP automatically, because the corresponding WHL version and EXE version can not be found, fortunately, Pip is very force, automatic installation success:

Here before the automatic installation PIP will check the installation of NumPy and scipy, if not properly installed PIP will be numpy and scipy installation (of course we do not want it to do so), and then install Theano, about five minutes, download completed, installation success.

2, Installation g++

First, here's a g++: g++

After installing Theano, let's test it first:

Obviously, Python hints that we don't have g++, and then we install one.

So the question is, I'm a 64-bit windows,32 python, so should we pack 64 g++ or 32-bit g++? After an attempt, a 64-bit g++ is required. It makes sense to think, because g++ and Python are not bound.

This gives the 64-bit MINGW: 64-bit MinGW. When the download is complete, double-click to install:

Click Next, select the following in the Configuration screen, click Next:

Because the compiler is installed by default on the C drive, click Next:

The process will be relatively lengthy, about 10 minutes or so:

Click Next and the installation is complete. Next, add the path C:\Program Files (x86) \mingw-w64\i686-5.2.0-posix-dwarf-rt_v4-rev1\mingw32\bin to the environment variable (the paths of different computers may be slightly different). Test the Theano again at this point and the installation succeeds:

Third, Test Theano

Just the import statement, you may not be quite sure of the correctness of the Theano library installation, and then we run one of the small test functions. However, it is necessary to install the Nose module first, it is recommended to use PIP for automatic installation:

If the network speed is smooth, it should be installed in a few seconds, test Theano again:

Note that the Theano installation is completed successfully, the warning given here is that we have not yet done the GPU configuration, which is said later, because Theano is CPU-supported.

Configuration under the four-, 32-bit system

Just talking about configuring 32-bit Python under a 64-bit system, and then talking about how to configure a 32-bit Python Theano library under a 32-bit system. First install the four libraries of NumPy, scipy, Libpython, Theano, which are installed exactly as they were installed (because they are all 32-bit python). The only difference is the installation of the g++, obviously the 32-bit system needs to install 32-bit g++:

Double click to enter the installation screen, click Next, select the Download latest version option:

Click Next, accept the agreement, next, specify the installation path (also here is the C drive):

Click Next to select the C and C + + compilers:

Click Next, click Install, start the installation, and note that the installation here is done automatically under the DOS interface:

After the installation is complete, add the path to the Bin folder under the installation directory to the environment variable, and the 32-bit g++ installation is complete. Here are two things to note:

(1) In accordance with the method provided by Baidu, through the download to install 32-bit g++, has been prompted to fail, the reason is unknown.

(2) 32-bit g++ and 64-bit g++ cannot coexist in environment variables, otherwise an unknown error is thrown. This also tells us that in the configuration environment variables must be careful to delete the failure path in time, one is to ensure the security of the system, so as to maintain the cleanliness of environmental variables.

  

Python Configuration third-party library Theano the road of twists and turns

Related Article

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.