在macOS Sierra 10.12.6上,LD_LIBRARY_PATH
,os.system()
和subprocess.run()
无法使用环境变量subprocess.Popen()
,即使PATH
可以正常使用。 Python版本为3.6.1
。但是在Linux(Ubuntu 17.10)上,这个环境变量也可以正确使用。以下python脚本envv.py
可以显示此问题:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import os
import time
PATH = "PATH"
print(os.environ.get(PATH))
os.system("echo $" + PATH)
subprocess.run("echo $" + PATH, shell=True)
subprocess.run("/bin/echo $" + PATH, shell=True)
subprocess.run("/bin/echo $" + PATH, shell=True, env={PATH: os.environ.get(PATH)})
subprocess.run("/bin/echo $" + PATH, shell=True, env=os.environ)
subprocess.Popen("/bin/echo $" + PATH, shell=True, env=os.environ.copy())
time.sleep(2)
print('\n')
LD_LIBRARY_PATH = "LD_LIBRARY_PATH"
print(os.environ.get(LD_LIBRARY_PATH))
os.system("echo $" + LD_LIBRARY_PATH)
subprocess.run("/bin/echo $" + LD_LIBRARY_PATH, shell=True)
subprocess.run("/bin/echo $" + LD_LIBRARY_PATH, shell=True, env={LD_LIBRARY_PATH: os.environ.get(LD_LIBRARY_PATH)})
subprocess.run("/bin/echo $" + LD_LIBRARY_PATH, shell=True, env=os.environ)
subprocess.Popen("/bin/echo $" + LD_LIBRARY_PATH, shell=True, env=os.environ.copy())
time.sleep(2)
print('\n')
在macOS上,输出为
$ python3 envv.py
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/bin:...
/opt/alps/lib:...
$ # use $ to show blank line
$
....
在Linux上,输出是
$ python3 envv.py
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
/opt/intel/compilers_and_libraries_2018.1.163/linux/compiler/lib/intel64:...
有没有人有任何想法?非常感谢!
更新2018-02-07
按照@GrahamDumpleton的建议,我尝试DYLD_LIBRARY_PATH
,但结果相同。测试条是
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import os
DYLD_LIBRARY_PATH = "DYLD_LIBRARY_PATH"
print(os.environ.get(DYLD_LIBRARY_PATH))
os.system("echo $" + DYLD_LIBRARY_PATH)
subprocess.run("/bin/echo $" + DYLD_LIBRARY_PATH, shell=True)
subprocess.run("/bin/echo $" + DYLD_LIBRARY_PATH, shell=True, env={DYLD_LIBRARY_PATH: os.environ.get(DYLD_LIBRARY_PATH)})
subprocess.run("/bin/echo $" + DYLD_LIBRARY_PATH, shell=True, env=os.environ)
subprocess.Popen("/bin/echo $" + DYLD_LIBRARY_PATH, shell=True, env=os.environ.copy())
相关输出
$ python3 envv.py
/opt/intel/compilers_and_libraries_2018.1.126/mac/compiler/lib:...
$
$
...
答案 0 :(得分:0)
如果您将chainWebpack: (config) => {
const tsRule = config.module.rule("ts");
tsRule.uses.clear();
tsRule
.use("cache-loader")
.loader("cache-loader")
.end()
.use("babel-loader")
.loader("babel-loader")
.end()
.use("auto-inject-async-catch-loader")
.loader("auto-inject-async-catch-loader")
.tap(() => {
return {
catchCode: 'console.error(e)'
}
})
.end()
.use("ts-loader")
.loader("ts-loader")
.tap(() => {
return {
transpileOnly: true,
appendTsSuffixTo: [
'\\.vue$'
],
happyPackMode: false
}
})
.end()
}
与subprocess.Popen
结合使用,则可以手动传播shell=True
和LD_LIBRARY_PATH
变量,如下所示:
DYLD_LIBRARY_PATH