Python模块在bash中返回错误,但不是来自空闲

Python模块在bash中返回错误,但不是来自空闲,python,macos,python-import,python-idle,fuzzywuzzy,Python,Macos,Python Import,Python Idle,Fuzzywuzzy,我是一个新手程序员,第一次在这里发帖。如有任何建议或建议,将不胜感激!我正在做一个项目,比较test.csv和ref.csv(两列都包含3-4个单词的字符串)的内容,并根据test.csv中每个字符串与ref.csv中最相似字符串的相似性为每个字符串分配分数。我正在使用字符串匹配模块来分配相似性分数 以下代码段获取两个输入文件,将它们转换为数组,然后打印出数组: import csv # Load text matching module from fuzzywuzzy import fuzz

我是一个新手程序员,第一次在这里发帖。如有任何建议或建议,将不胜感激!我正在做一个项目,比较test.csv和ref.csv(两列都包含3-4个单词的字符串)的内容,并根据test.csv中每个字符串与ref.csv中最相似字符串的相似性为每个字符串分配分数。我正在使用字符串匹配模块来分配相似性分数

以下代码段获取两个输入文件,将它们转换为数组,然后打印出数组:

import csv

# Load text matching module
from fuzzywuzzy import fuzz
from fuzzywuzzy import process


# Import reference and test lists and assign to variables
ref_doc = csv.reader(open('ref.csv', 'rb'), delimiter=",", quotechar='|')
test_doc = csv.reader(open('test.csv', 'rb'), delimiter=",", quotechar='|')

# Define the arrays into which to load these lists
ref = []
test = []

# Assign the reference and test docs to arrays
for row in ref_doc:
    ref.append(row)

for row in test_doc:
    test.append(row)

# Print the arrays to make sure this all worked properly
# before we procede to run matching operations on the arrays
print ref, "\n\n\n", test
问题是,当我在空闲状态下运行该脚本时,它会按预期工作,但当我从bash调用它时,返回以下错误:

['one', 'two']
Traceback (most recent call last):
  File "csvimport_orig.py", line 4, in <module>
    from fuzzywuzzy import fuzz
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fuzzywuzzy/fuzz.py", line 32, in <module>
    import utils
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/fuzzywuzzy/utils.py", line 6, in <module>
    table_from=string.punctuation+string.ascii_uppercase
AttributeError: 'module' object has no attribute 'punctuation'
['1','2']
回溯(最近一次呼叫最后一次):
文件“csvimport_orig.py”,第4行,在
从fuzzyfuzzy导入fuzz
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/fuzzywuzzy/fuzz.py”,第32行,在
导入UTIL
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/fuzzywuzzy/utils.py”,第6行,在
table_from=string.标点符号+string.ascii_大写字母
AttributeError:“模块”对象没有属性“标点”
我需要在bash中配置什么才能正常工作吗?还是有什么根本性的错误,IDLE没有抓住?为了简单起见,我在这段代码中没有调用fuzzyfuzzy模块,但它在IDLE中的工作与预期的一样

最后,我想使用,但在我投入额外的时间来完成这项工作之前,我试图看看我对这个脚本的使用是否有价值


提前感谢。

几乎可以肯定,您有一个名为
string.py
的模块正在加载,而不是stdlib的
string.py
模块

您可以通过添加行来确认这一点

import string
print string
到您的
csvimport_u orig.py
程序。这应该显示类似于

<module 'string' from '/usr/lib/python2.7/string.pyc'>

或者,代替
string.py
,在冲突库所在的位置。重命名
string.py
模块。

几乎可以肯定,您有一个名为
string.py
的模块,正在加载该模块,而不是stdlib的
string.py
模块

您可以通过添加行来确认这一点

import string
print string
到您的
csvimport_u orig.py
程序。这应该显示类似于

<module 'string' from '/usr/lib/python2.7/string.pyc'>

或者,代替
string.py
,在冲突库所在的位置。重命名您的
string.py
模块。

您调用了它。我的脚本所在的目录中有一个string.py文件,这就是我的错误消息中的['one','two']的来源。重命名了文件,现在脚本按预期工作。谢谢,你叫的。我的脚本所在的目录中有一个string.py文件,这就是我的错误消息中的['one','two']的来源。重命名了文件,现在脚本按预期工作。非常感谢。