python - 从 Windows 到 Ubuntu 的 python 错误
问题描述
我有一个 python 脚本,它接受一个命令行参数,一个包含数据的目录,即python3 test.py /data/
我在 Windows 机器上用 Jupyter 编写了它。我在 Windows 终端中测试脚本,一切正常。我需要它在 Ubuntu 机器上运行。我下载了 Ubuntu LiveCD 只是为了测试它。我进入脚本和数据所在文件夹中的 Ubuntu 终端。我输入了这个确切的行:
python3 test.py /data/
我在第 91 行得到一个语法错误
image = plt.imread(directory_name + "image-" + f"{i:02d}" + ".jpg")
箭头指向 f"{i:02d}" 中的第二个“。我也尝试输入
python3 test.py
没有目录,我得到了同样的错误。奇怪的是我写了 try/except 来将目录存储到变量中,如果格式错误则抛出异常。同样,它在 Windows 中运行良好。这是 try/except 的代码:
#import directory location of images, catch exceptions
import sys
try:
directory_name = sys.argv[1]
print(directory_name)
except:
print('Please pass directory_name')
请注意,它不会在 Ubuntu 中打印目录名称。我假设我收到错误是因为 Windows 的目录语法与 Ubuntu 的不同(我不太熟悉)。我该如何解决?
这是我看到的错误:
代码如上所述。脚本中的第一件事是 try/except,然后是几个自定义函数,然后是给出错误的行。
解决方案
检查 Ubuntu 上的安装库。它没有预装在系统中,您使用。
import mathplotlib as plt
image = plt.imread(directory_name + "image-" + f"{i:02d}" + ".jpg")
推荐阅读
- apache-spark - 使用 Apache Spark 的代理键
- c# - 从两个 IEnumerable 创建一个 IEnumerable 队列
- python-3.x - Groupby、means 和 std
- google-chrome-extension - Chrome 扩展程序。后台 JS、AJAX 请求、DNS 查找和 SSL 握手时间
- ios - 使用自定义字段 Swift 从数组中搜索
- php - 是否可以使用单个键绑定注释掉一行混合语法代码(PHP + HTML)?
- angular - CdkDragAndDrop如何防止拖拽
- jquery - 按类名递归查找下一节
- javascript - 一系列 Promise 是如何与 reduce 一起工作的?
- android - Nativescript 构建失败