提交 ab94990c authored 作者: Ray Donnelly's avatar Ray Donnelly

Conda: Enable use of mingw-w64 g++ and mkl when not on PATH

Many Windows users avoid the command-line and are unfamiliar with env. vars. They can elect to use Anaconda/Miniconda Python as their system Python and in that case would not be able to take advantage of g++ or mkl. This commit works around these issues by adding the appropriate values to os.environ['PATH'] if they are not already on PATH.
上级 dbc63c99
...@@ -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("conda g++ not available, use `conda install m2w64-toolchain`")
if rc != 0: if rc != 0:
param = "" param = ""
...@@ -1269,6 +1283,7 @@ def default_blas_ldflags(): ...@@ -1269,6 +1283,7 @@ def default_blas_ldflags():
blas_info.get('library_dirs', [])]) blas_info.get('library_dirs', [])])
res = try_blas_flag(flags) res = try_blas_flag(flags)
if res: if res:
maybe_add_to_os_environ_pathlist('PATH', lib_path)
return 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
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论