提交 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 ...@@ -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 version supporting Visual Studio 2008), and GCC (for non-CUDA C code
generated by Theano). generated by Theano).
.. _gpu_windows: .. _gpu_windows:
Visual Studio and CUDA Visual Studio and CUDA
...@@ -108,6 +110,26 @@ during installation: ...@@ -108,6 +110,26 @@ during installation:
Scientific Python distribution 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 We highly recommend the Pierre Raybaut's `WinPython
<http://winpython.sourceforge.net/>`_ distribution - it is compiled <http://winpython.sourceforge.net/>`_ distribution - it is compiled
for both 32- and 64-bit systems, links against the fast `MKL for both 32- and 64-bit systems, links against the fast `MKL
...@@ -178,23 +200,6 @@ can download the installation for free. ...@@ -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) Alternative: Python(x,y)
++++++++++++++++++++++++ ++++++++++++++++++++++++
...@@ -358,10 +363,10 @@ most useful, because you can update it with a single ``git pull`` ...@@ -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 command. Therefore we recommend it. However, a manual install without
Git is also possible. Git is also possible.
Git Install Git Install
########### ###########
Theano is hosted on GitHub, you need Git to download it. For Windows, Theano is hosted on GitHub, you need Git to download it. For Windows,
download and install the `MSYSGIT <http://msysgit.github.io/>`_ build. download and install the `MSYSGIT <http://msysgit.github.io/>`_ build.
Open up the `Git Shell` in the directory in which you want to install Open up the `Git Shell` in the directory in which you want to install
......
...@@ -31,10 +31,6 @@ import logging ...@@ -31,10 +31,6 @@ import logging
import sys 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") theano_logger = logging.getLogger("theano")
logging_default_handler = logging.StreamHandler() logging_default_handler = logging.StreamHandler()
logging_default_formatter = logging.Formatter( logging_default_formatter = logging.Formatter(
......
...@@ -107,3 +107,30 @@ class DefaultOrderedDict(OrderedDict): ...@@ -107,3 +107,30 @@ class DefaultOrderedDict(OrderedDict):
return type(self)(self.default_factory, self) return type(self)(self.default_factory, self)
__all__ += ['DefaultOrderedDict'] __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, ...@@ -19,6 +19,7 @@ from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
TheanoConfigParser, THEANO_FLAGS_DICT) TheanoConfigParser, THEANO_FLAGS_DICT)
from theano.misc.cpucount import cpuCount from theano.misc.cpucount import cpuCount
from theano.misc.windows import call_subprocess_Popen, output_subprocess_Popen 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') _logger = logging.getLogger('theano.configdefaults')
...@@ -418,6 +419,19 @@ try: ...@@ -418,6 +419,19 @@ try:
except OSError: except OSError:
rc = 1 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: if rc != 0:
param = "" param = ""
...@@ -1237,39 +1251,38 @@ def default_blas_ldflags(): ...@@ -1237,39 +1251,38 @@ def default_blas_ldflags():
['-l%s' % l for l in ["mk2_core", "mk2_intel_thread", ['-l%s' % l for l in ["mk2_core", "mk2_intel_thread",
"mk2_rt"]]) "mk2_rt"]])
# Anaconda # MKL
if "Anaconda" in sys.version or "Continuum" in sys.version: # If mkl can be imported then use it. On conda:
# If the "mkl-service" conda package (available # "conda install mkl-service" installs the Python wrapper and
# through Python package "mkl") is installed and # the low-level C libraries as well as optimised version of
# importable, then the libraries (installed by conda # numpy and scipy.
# package "mkl-rt") are actually available. Using try:
# "conda install mkl" will install both, as well as import mkl # noqa
# optimized versions of numpy and scipy. except ImportError as e:
try: if any([m for m in ('conda', 'Continuum') if m in sys.version]):
import mkl # noqa _logger.warning('install mkl with `conda install mkl-service`: %s', e)
except ImportError as e: else:
_logger.info('Conda mkl is not available: %s', e) # 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: else:
# This branch is executed if no exception was raised lib_path = blas_info.get('library_dirs', [])
if sys.platform == "win32": flags = []
lib_path = os.path.join(sys.prefix, 'DLLs') if lib_path:
flags = ['-L"%s"' % lib_path] flags = ['-L%s' % lib_path[0]]
else: flags += ['-l%s' % l for l in ["mkl_core",
lib_path = blas_info.get('library_dirs', []) "mkl_intel_thread",
flags = [] "mkl_rt"]]
if lib_path: res = try_blas_flag(flags)
flags = ['-L%s' % lib_path[0]] if res:
flags += ['-l%s' % l for l in ["mkl_core", return res
"mkl_intel_thread", flags.extend(['-Wl,-rpath,' + l for l in
"mkl_rt"]] blas_info.get('library_dirs', [])])
res = try_blas_flag(flags) res = try_blas_flag(flags)
if res: if res:
return res maybe_add_to_os_environ_pathlist('PATH', lib_path[0])
flags.extend(['-Wl,-rpath,' + l for l in return res
blas_info.get('library_dirs', [])])
res = try_blas_flag(flags)
if res:
return res
# to support path that includes spaces, we need to wrap it with double quotes on Windows # to support path that includes spaces, we need to wrap it with double quotes on Windows
path_wrapper = "\"" if os.name == 'nt' else "" path_wrapper = "\"" if os.name == 'nt' else ""
...@@ -1298,13 +1311,10 @@ def default_blas_ldflags(): ...@@ -1298,13 +1311,10 @@ def default_blas_ldflags():
if res: if res:
return res return res
# Try to add the anaconda lib directory to runtime loading of lib. # Add sys.prefix/lib to the runtime search path. On
# This fix some case with Anaconda 2.3 on Linux. # non-system installations of Python that use the
# Newer Anaconda still have this problem but only have # system linker, this is generally neccesary.
# Continuum in sys.version. if sys.platform in ("linux", "darwin"):
if (("Anaconda" in sys.version or
"Continuum" in sys.version) and
"linux" in sys.platform):
lib_path = os.path.join(sys.prefix, 'lib') lib_path = os.path.join(sys.prefix, 'lib')
ret.append('-Wl,-rpath,' + lib_path) ret.append('-Wl,-rpath,' + lib_path)
res = try_blas_flag(ret) res = try_blas_flag(ret)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论