提交 08b6405c authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5290 from mingwandroid/conda-fixes

Conda fixes
......@@ -32,6 +32,8 @@ C/C++ (for Python 2.7 family this has to be Microsoft Visual Studio
version supporting Visual Studio 2008), and GCC (for non-CUDA C code
generated by Theano).
.. _gpu_windows:
Visual Studio and CUDA
......@@ -108,6 +110,26 @@ during installation:
Scientific Python distribution
##############################
Recommended: Anaconda
+++++++++++++++++++++
ContinuumIO_ provides a free Python distribution for all 3 main desktop
operating systems, including Windows 32-bit and 64-bit, and includes
Theano and all of its dependencies. This is one of the the easiest ways
to get Theano on Windows. Simply download and execute the installer from the
`Anaconda download page <https://www.continuum.io/downloads>`__,
and execute the following from the ``Anaconda Prompt``:
.. _ContinuumIO: http://continuum.io
.. code-block:: bash
$ conda install theano
Alternative: WinPython
++++++++++++++++++++++
We highly recommend the Pierre Raybaut's `WinPython
<http://winpython.sourceforge.net/>`_ distribution - it is compiled
for both 32- and 64-bit systems, links against the fast `MKL
......@@ -178,23 +200,6 @@ can download the installation for free.
Alternative: Anaconda
+++++++++++++++++++++++
ContinuumIO_ is providing a free Python distribution for Windows (32-bit
and 64-bit), including all dependencies of Theano. If you are not
eligible for a download of EPD or Canopy (via a commercial, or free academic
licence), this is the easiest way to install
Theano's dependencies. Simply download and execute the installer from
`Anaconda download page <https://store.continuum.io/cshop/anaconda/>`__,
and execute the following in Windows command line:
.. _ContinuumIO: http://continuum.io
.. code-block:: bash
$ conda install mingw libpython
Alternative: Python(x,y)
++++++++++++++++++++++++
......@@ -358,10 +363,10 @@ most useful, because you can update it with a single ``git pull``
command. Therefore we recommend it. However, a manual install without
Git is also possible.
Git Install
###########
Theano is hosted on GitHub, you need Git to download it. For Windows,
download and install the `MSYSGIT <http://msysgit.github.io/>`_ build.
Open up the `Git Shell` in the directory in which you want to install
......
......@@ -31,10 +31,6 @@ import logging
import sys
if sys.platform == 'win32' and sys.version_info[0:2] == (3, 5):
raise RuntimeError(
"Theano do not support Python 3.5 on Windows. Use Python 2.7 or 3.4.")
theano_logger = logging.getLogger("theano")
logging_default_handler = logging.StreamHandler()
logging_default_formatter = logging.Formatter(
......
......@@ -107,3 +107,30 @@ class DefaultOrderedDict(OrderedDict):
return type(self)(self.default_factory, self)
__all__ += ['DefaultOrderedDict']
def maybe_add_to_os_environ_pathlist(var, newpath):
'''Unfortunately, Conda offers to make itself the default Python
and those who use it that way will probably not activate envs
correctly meaning e.g. mingw-w64 g++ may not be on their PATH.
This function ensures that, if `newpath` is an absolute path,
and it is not already in os.environ[var] it gets added to the
front.
The reason we check first is because Windows environment vars
are limited to 8191 characters and it is easy to hit that.
`var` will typically be 'PATH'. '''
import os
if os.path.isabs(newpath):
try:
oldpaths = os.environ[var].split(os.pathsep)
if newpath not in oldpaths:
newpaths = os.pathsep.join([newpath] + oldpaths)
os.environ[var] = newpaths
except:
pass
__all__ += ['maybe_add_to_os_environ_pathlist']
......@@ -19,6 +19,7 @@ from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
TheanoConfigParser, THEANO_FLAGS_DICT)
from theano.misc.cpucount import cpuCount
from theano.misc.windows import call_subprocess_Popen, output_subprocess_Popen
from theano.compat import maybe_add_to_os_environ_pathlist
_logger = logging.getLogger('theano.configdefaults')
......@@ -418,6 +419,19 @@ try:
except OSError:
rc = 1
# Anaconda on Windows has mingw-w64 packages including GCC, but it may not be on PATH.
if rc != 0:
if sys.platform == "win32":
mingw_w64_gcc = os.path.join(os.path.dirname(sys.executable), "Library", "mingw-w64", "bin", "g++")
try:
rc = call_subprocess_Popen([mingw_w64_gcc, '-v'])
if rc == 0:
maybe_add_to_os_environ_pathlist('PATH', os.path.dirname(mingw_w64_gcc))
except OSError:
rc = 1
if rc != 0:
_logger.warning("g++ not available, if using conda: `conda install m2w64-toolchain`")
if rc != 0:
param = ""
......@@ -1237,39 +1251,38 @@ def default_blas_ldflags():
['-l%s' % l for l in ["mk2_core", "mk2_intel_thread",
"mk2_rt"]])
# Anaconda
if "Anaconda" in sys.version or "Continuum" in sys.version:
# If the "mkl-service" conda package (available
# through Python package "mkl") is installed and
# importable, then the libraries (installed by conda
# package "mkl-rt") are actually available. Using
# "conda install mkl" will install both, as well as
# optimized versions of numpy and scipy.
try:
import mkl # noqa
except ImportError as e:
_logger.info('Conda mkl is not available: %s', e)
# MKL
# If mkl can be imported then use it. On conda:
# "conda install mkl-service" installs the Python wrapper and
# the low-level C libraries as well as optimised version of
# numpy and scipy.
try:
import mkl # noqa
except ImportError as e:
if any([m for m in ('conda', 'Continuum') if m in sys.version]):
_logger.warning('install mkl with `conda install mkl-service`: %s', e)
else:
# This branch is executed if no exception was raised
if sys.platform == "win32":
lib_path = [os.path.join(sys.prefix, 'Library', 'bin')]
flags = ['-L"%s"' % lib_path]
else:
# This branch is executed if no exception was raised
if sys.platform == "win32":
lib_path = os.path.join(sys.prefix, 'DLLs')
flags = ['-L"%s"' % lib_path]
else:
lib_path = blas_info.get('library_dirs', [])
flags = []
if lib_path:
flags = ['-L%s' % lib_path[0]]
flags += ['-l%s' % l for l in ["mkl_core",
"mkl_intel_thread",
"mkl_rt"]]
res = try_blas_flag(flags)
if res:
return res
flags.extend(['-Wl,-rpath,' + l for l in
blas_info.get('library_dirs', [])])
res = try_blas_flag(flags)
if res:
return res
lib_path = blas_info.get('library_dirs', [])
flags = []
if lib_path:
flags = ['-L%s' % lib_path[0]]
flags += ['-l%s' % l for l in ["mkl_core",
"mkl_intel_thread",
"mkl_rt"]]
res = try_blas_flag(flags)
if res:
return res
flags.extend(['-Wl,-rpath,' + l for l in
blas_info.get('library_dirs', [])])
res = try_blas_flag(flags)
if res:
maybe_add_to_os_environ_pathlist('PATH', lib_path[0])
return res
# to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else ""
......@@ -1298,13 +1311,10 @@ def default_blas_ldflags():
if res:
return res
# Try to add the anaconda lib directory to runtime loading of lib.
# This fix some case with Anaconda 2.3 on Linux.
# Newer Anaconda still have this problem but only have
# Continuum in sys.version.
if (("Anaconda" in sys.version or
"Continuum" in sys.version) and
"linux" in sys.platform):
# Add sys.prefix/lib to the runtime search path. On
# non-system installations of Python that use the
# system linker, this is generally neccesary.
if sys.platform in ("linux", "darwin"):
lib_path = os.path.join(sys.prefix, 'lib')
ret.append('-Wl,-rpath,' + lib_path)
res = try_blas_flag(ret)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论