我有一个虚拟环境,我在其中安装了Python。当我打字时
which python
我得到:
^{pr2}$我在这里导入numpy没有错误:
(my_env) user@hostname:~/my_dir$ python
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>>
但当我在python程序中说“import numpy as np”并从shell脚本运行它时,我得到:
(my_env) user@hostname:~/mydir$ ./program.sh
Traceback (most recent call last):
File "../python_program.py", line 3, in <module>
import numpy as np
ImportError: No module named numpy
我该怎么解决这个问题?在
编辑:有人问我里面有什么程序.sh简而言之,我在一个循环中运行不同的参数。长话短说是:
#/bin/bash
i=0
while read a1 b1 c1 d1 e1 f1 g1 h1 i1
do
i=$(($i+1))
mkdir RUN_EXP$i
cp $a1 RUN_EXP$i
cd RUN_EXP$i
../python_program.py --filename $a1 --reps $b1 --pop $c1 --susc $d1 --exp_trans $e1 --inf_period $f1\ $g1 --eps $h1\ $i1
cd ..
done < readparas.txt
文件readtxt.txt段落包含文件名、reps、pop、susc、exp_trans、inf_period和eps的行如下:
run_1.txt 50 162 0.30 0.1 5 9 0.1 0.25
run_1.txt 50 162 0.30 0.3 5 9 0.1 0.25
...
shell脚本不关心
virtualenv
活动(它在干净的环境中启动)。在您需要有完整的可执行路径,而不是
../python_program.py
或者您可以将其附加到
^{pr2}$python_program.py
的顶部参考:The importance of env (and how it works with virtualenv)
相关问题 更多 >
编程相关推荐