python - 没有名为 csv 的模块

使用

  • Windows 7
  • Mercurial 3.4.1 与 Python 2.7.9

在控制台窗口中执行 hg dummy 时,python 脚本(如下)会产生以下控制台输出。

start reading file
abort: No module named csv!

这是 python 脚本:

import csv
import sys

def dummy(ui, repo, node, **opts)
  with open('file.csv', 'rb') as csvfile:
    print 'start reading file'
    reader = csv.reader(csvfile)
    print 'finished reading file'

cmdtable = {
  'dummy': (dummy, 
  [('', '', None, '')], '',)
}

尝试使用 csv 文件的绝对路径,但没有帮助。

所有在线示例都使用“import csv”并且似乎有效。

是什么导致了这个问题? python 是默认带有 csv 支持还是这个插件?

最佳答案

Python 确实支持 csv。我按照 alexis 的建议使用了 print sys.path,发现 Mercurial 引用了 ..\Program Files\TortoiseHg\library.zip 而不是实际的 Python 安装文件夹。将 Python 安装文件夹中的 csv.py 复制到 Mercurial library.zip 文件中解决了这个问题。

https://stackoverflow.com/questions/33411131/

相关文章:

pdf - 有没有一种方法可以自动化/编写脚本(例如 perl)标记的 pdf 文件以查看它是否符合

php - Wordpress 如何向所有 SETCOOKIE() 函数添加 httponly 和安

ios - AVSampleBufferDisplayLayer : change videoGra

multithreading - 每个连接的 Netty 多线程

python - 在 OpenGL 中的 3D 模型后面绘制背景视频

jsp - 带有 Tomcat 的 Intellij IDEA HotSwap 适用于类,但不适用于

xaml - 在 UWP 应用程序中覆盖来自 Generic.xaml 的资源

nginx - Kong 拒绝将自定义插件识别为已启用

python - flask 迁移 : Alembic converting choices int

java - 如何为 Selenium Grid 中的 session 提供无限空闲时间,但清理断开