Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python numpy在cmd行中找到,但在脚本中找不到_Python_Numpy_Terminal_Scripting_Pythonpath - Fatal编程技术网

Python numpy在cmd行中找到,但在脚本中找不到

Python numpy在cmd行中找到,但在脚本中找不到,python,numpy,terminal,scripting,pythonpath,Python,Numpy,Terminal,Scripting,Pythonpath,当我从命令行启动python并导入numpy时,它工作得很好。当我运行与脚本相同的代码时,它会失败。这是在公司IT管理下的centos盒上(没有我自己可以安装的东西),我可能只是在我的.cshrc中遗漏了一些东西,但是呢 来自命令行: % python Python 2.7.11 (default, Oct 7 2016, 09:54:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help", "copyright",

当我从命令行启动python并导入numpy时,它工作得很好。当我运行与脚本相同的代码时,它会失败。这是在公司IT管理下的centos盒上(没有我自己可以安装的东西),我可能只是在我的.cshrc中遗漏了一些东西,但是呢

来自命令行:

% python
Python 2.7.11 (default, Oct  7 2016, 09:54:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import argparse
>>> from scipy.interpolate import interp1d
>>> 
#! /usr/bin/python 

import os.path
import numpy as np
import matplotlib.pyplot as plt
import argparse
from scipy.interpolate import interp1d
% ./inter.py
Traceback (most recent call last):
  File "./inter.py", line 4, in <module>
    import numpy as np
ImportError: No module named numpy
与脚本相同:

% python
Python 2.7.11 (default, Oct  7 2016, 09:54:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import argparse
>>> from scipy.interpolate import interp1d
>>> 
#! /usr/bin/python 

import os.path
import numpy as np
import matplotlib.pyplot as plt
import argparse
from scipy.interpolate import interp1d
% ./inter.py
Traceback (most recent call last):
  File "./inter.py", line 4, in <module>
    import numpy as np
ImportError: No module named numpy
给出以下错误:

% python
Python 2.7.11 (default, Oct  7 2016, 09:54:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import argparse
>>> from scipy.interpolate import interp1d
>>> 
#! /usr/bin/python 

import os.path
import numpy as np
import matplotlib.pyplot as plt
import argparse
from scipy.interpolate import interp1d
% ./inter.py
Traceback (most recent call last):
  File "./inter.py", line 4, in <module>
    import numpy as np
ImportError: No module named numpy
%./inter.py
回溯(最近一次呼叫最后一次):
文件“/inter.py”,第4行,在
将numpy作为np导入
ImportError:没有名为numpy的模块

非常感谢您的反馈。

您可能无意中引用了不同的Python安装。

尝试修改这行代码/usr/bin/python到
#/usr/bin/env python
。也就是说,脚本引用的Python可能与
$PATH
中的Python不同。您可以通过比较脚本的Python(
/usr/bin/Python
)与以下命令的结果来确认这一点:
哪个Python


在本例中,我们使用
env
来确保脚本使用的Python解释器是可在
$PATH

中访问的解释器。您可能无意中引用了不同的Python安装。尝试修改这行代码/usr/bin/python到
#/usr/bin/env python
。使用“python inter.py”启动。这样,您甚至不需要将其设置为可执行。@liliscent:没错,但它是不可编程的。OP如何在更一般的情况下使用它来自动化某些任务?