如何从不同的目录运行matplotlib python脚本?

时间:2017-11-22 17:05:57

标签: python matplotlib

我正在尝试从不同的目录运行python / matplotlib绘图脚本,并且收到有关matplotlib import的错误。

所以在我正在运行的包含数据的目录中:

python /home/birac/SCRIPTS/plot.py data.txt

plot.py是:

#!/home/birac/anaconda2/bin/python
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import sys
filename = sys.argv[1]
xdata, ydata = np.loadtxt(fname=filename, comments='@', usecols=(0,1), unpack=True)
plt.plot(xdata, ydata, color='gray', marker='.', markersize=0)
plt.savefig('graph.png')

然而,它给我一个关于我的matplotlib导入的奇怪错误:

 Traceback (most recent call last):
  File "/home/birac/SCRIPTS/plot.py", line 3, in <module>
    import matplotlib
  File "/opt/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 128, in <module>
    from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/opt/anaconda/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/opt/anaconda/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 26, in <module>
    from pyparsing import (Literal, ZeroOrMore, Optional, Regex, StringEnd,
  File "/opt/anaconda/lib/python2.7/site-packages/pyparsing.py", line 69, in <module>
    import copy
  File "/home/birac/SCRIPTS/copy.py", line 17, in <module>
    extent possible) inserts *the same objects* into it that the
  File "/opt/anaconda/lib/python2.7/shutil.py", line 119, in copy
    copyfile(src, dst)
  File "/opt/anaconda/lib/python2.7/shutil.py", line 82, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'ayeg_subs_100ns.pdb'

I / O错误是指文件'ayeg_subs_100ns.pdb',它在任一目录中都不存在。

基本上似乎不是导入python拷贝模块,而是试图在本地目录中找到一个名为'copy.py'的脚本,该脚本不存在。

我可以从同一目录或另一个目录运行该文件,但我很好奇为什么这是来自这个特定目录的问题。

0 个答案:

没有答案