简体   繁体   English

如何在 Windows 上的 Anaconda Python 2.7 x64 上安装 Theano?

[英]How to install Theano on Anaconda Python 2.7 x64 on Windows?

I wonder how to install Theano on Anaconda Python 2.7 x64 on Windows 7 x64.我想知道如何在 Windows 7 x64 上的 Anaconda Python 2.7 x64 上安装 Theano。 The Theano website provides some instructions but is not clear as to what is specific to Anaconda. Theano 网站提供了一些说明,但不清楚 Anaconda 的具体内容。

I'm not 100% certain but this may be a minimal set of instructions, but only if you don't want to use a GPU.我不是 100% 肯定,但这可能是最少的指令集,但前提是您不想使用 GPU。 Getting Theano to use a GPU on Windows is quite a bit more difficult.让 Theano 在 Windows 上使用 GPU 有点困难。

  1. Install TDM GCC x64.安装TDM GCC x64。
  2. Install Anaconda x64.安装 Anaconda x64。
  3. run conda update conda .运行conda update conda
  4. run conda update --all .运行conda update --all
  5. run conda install mingw libpython .运行conda install mingw libpython
  6. Install Theano (how you do this depends on whether you want to interact with the Theano source code or not, and whether you want the "bleeding edge" version, or are happy with the last, but out-of-date major release).安装 Theano(如何安装取决于您是否想要与 Theano 源代码交互,以及您是否想要“出血边缘”版本,或者对最后一个但过时的主要版本感到满意)。
    1. Older version : eg pip install Theano . 旧版本:例如pip install Theano
    2. Bleeding edge version : eg pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git (see linked documentation for more options) 出血边缘版本:例如pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git (有关更多选项,请参阅链接文档)

If you want multithreading support via OpenMP then things get more complicated.如果您希望通过 OpenMP 支持多线程,那么事情会变得更加复杂。

If you want GPU support things get much more complicated.如果您想要 GPU 支持,事情会变得更加复杂。

The Windows installation instructions in the Theano documentation are fragmented at best, and terribly out of date at worst. Theano 文档中的 Windows 安装说明充其量是零散的,最糟糕的是已经过时了。 If you need more than the basics working on Windows, you'll need to pick your way through to find an approach that works for you.如果您需要的不仅仅是在 Windows 上工作的基础知识,您将需要通过自己的方式找到适合您的方法。

The trick is that YOU NEED TO CREATE AN ENVIRONMENT/WORKSPACE FOR PYTHON .诀窍是您需要为 PYTHON 创建环境/工作区 This solution should work for Python 2.7 but at the time of writing keras can run on python 3.5, especially if you have the latest anaconda installed (this took me awhile to figure out so I'll outline the steps I took to install KERAS in python 3.5):这个解决方案应该适用于 Python 2.7,但在撰写本文时,keras 可以在 python 3.5 上运行,特别是如果你安装了最新的 anaconda(这花了我一段时间才弄清楚,所以我将概述我在 python 中安装 KERAS 所采取的步骤3.5):

-- CREATE ENVIRONMENT/WORKSPACE FOR PYTHON 3.5: --为 Python 3.5 创建环境/工作区:

  1. C:\\conda create --name neuralnets python=3.5
  2. C:\\activate neuralnets

-- INSTALL EVERYTHING (notice the neuralnets workspace in parenthesis on each line). --安装所有东西(注意每行括号中的神经网络工作区)。 ACCEPT ANY DEPENDENCIES EACH OF THOSE STEPS WANTS TO INSTALL :接受每个步骤要安装的任何依赖项

  1. (neuralnets) C:\\conda install theano
  2. (neuralnets) C:\\conda install mingw libpython
  3. (neuralnets) C:\\pip install tensorflow
  4. (neuralnets) C:\\pip install keras

-- TEST IT OUT: --测试一下:

(neuralnets) C:\python -c "from keras import backend; print(backend._BACKEND)"

Just remember, if you want to work in the workspace you always have to do:请记住,如果您想在工作区中工作,您必须始终执行以下操作:

C:\activate neuralnets

so you can launch Jypiter for example (assuming you also have jypiter installed in this environment/workspace) as:例如,您可以启动 Jypiter(假设您在此环境/工作区中还安装了 jypiter):

C:\activate neuralnets
(neuralnets) jypiter notebook

You can read more about managing and creating conda environments/workspaces at the follwing URL: https://conda.io/docs/using/envs.html您可以在以下 URL 中阅读有关管理和创建 conda 环境/工作区的更多信息: https : //conda.io/docs/using/envs.html

Adding GPU support is not that much more complicated (although not intuitive)添加 GPU 支持并没有那么复杂(虽然不直观)

  1. Install theano as in Daniel Renshaw's answer按照 Daniel Renshaw 的回答安装 theano
  2. Go to the "From Zero to Lasagne" tutorial, and follow it from the Nvidia GPU support (CUDA) section with the following changes:转到“从零到千层面”教程,并从Nvidia GPU support (CUDA)部分按照以下更改进行操作:
    • I installed visual studio 2013 community instead of the Windows SDK我安装了visual studio 2013 community而不是 Windows SDK
    • And .theanorc should be placed in C:\\Users\\USERNAME并且.theanorc应该放在C:\\Users\\USERNAME

If you need Theano on python 2.7 and you already installed Anaconda, you can type the following in a command prompt:如果你在 python 2.7 上需要 Theano 并且你已经安装了 Anaconda,你可以在命令提示符中键入以下内容:

conda create -n Python_27 python=2.7.16
conda activate Python_27
conda install numpy=1.12 scipy mkl-service libpython
conda install theano 

It appears that the windows python 2.7 numpy packages don't include the _mklinit patch.似乎 windows python 2.7 numpy 包不包含 _mklinit 补丁。 Either set the MKL_THREADING_LAYER in your env or update to python 3 which does have patched packages.在您的 env 中设置 MKL_THREADING_LAYER 或更新到具有修补程序包的 python 3。 You can type in your env:你可以输入你的环境:

python
import os
os.environ["MKL_THREADING_LAYER"] = "GNU"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM