简体   繁体   English

程序在Pycharm中运行,但不在终端中运行

[英]Program runs in Pycharm but not in terminal

I often run a program using terminal because that speeds things up by a factor of 3. I recently upgraded from a 2016 version of Pycharm to a 2017 version and now I can no longer run the program in terminal. 我经常使用终端运行程序,因为这样可以使速度提高3倍。我最近从2016版的Pycharm升级到了2017版,现在我不再可以在终端中运行该程序。 The line that the terminal does not like is: 终端不喜欢的行是:

wb4 = load_workbook('../temp_proof.xlsx')

Again, this line works fine with Pycharm. 同样,此行与Pycharm配合良好。 I went to the terminal and made sure it was in the right directory and when I pressed ls, that file is in the directory. 我去了终端,确保它在正确的目录中,当我按ls时,该文件在目录中。

Here is the terminal error message:
 File "/Users/bobsmith/PycharmProjects/inference_engine2/inference2/Proofs/prove.py", line 36, in <module>
    wb4 = load_workbook('../temp_proof.xlsx')

  File "/Library/Python/2.7/site-packages/openpyxl/reader/excel.py", line 151, in load_workbook
    archive = _validate_archive(filename)

  File "/Library/Python/2.7/site-packages/openpyxl/reader/excel.py", line 115, in _validate_archive
    archive = ZipFile(filename, 'r', ZIP_DEFLATED)

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/zipfile.py", line 756, in __init__
    self.fp = open(file, modeDict[mode])
IOError: [Errno 2] No such file or directory: '../temp_proof.xlsx'

For some reasons I had to put a slash in front of Users like so: 由于某些原因,我不得不在用户前面加一个斜杠,如下所示:

wb4 = load_workbook('/Users/bobsmith/PycharmProjects/inference_engine2/inference2/temp_proof.xlsx')

I thought I tried that before, but this time it worked. 我以为以前尝试过,但是这次可以了。 It also might be the case that I had to reconfigure my Pycharm working directory which I did. 也可能是我不得不重新配置我的Pycharm工作目录的情况。 So I'm not sure what the real cause was. 所以我不确定真正的原因是什么。

Its seems to get the abs path from the temp_proof.xlsx file location. 它似乎从temp_proof.xlsx文件位置获取abs路径。 do this below steps 请按照以下步骤操作

  1. Go to the folder path temp_proof.xlsx 转到文件夹路径temp_proof.xlsx
  2. open python interpreter from that location and find the abs path to the location ie python import os locpath=os.getcwd() 从该位置打开python解释器,然后找到该位置的abs路径,即python import os locpath = os.getcwd()
  3. use locpath value to access temp_proof.xlsx file ie filePath=os.path.join(locapth,'temp_proof.xlsx') 使用locpath值访问temp_proof.xlsx文件,即filePath = os.path.join(locapth,'temp_proof.xlsx')
  4. filePath you can use wb4 = load_workbook(filePath) 您可以使用的文件路径wb4 = load_workbook(filePath)

This will work 这会起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 脚本在 pycharm 中运行但不在 ubuntu 终端中运行 - Python script runs in pycharm but not in ubuntu terminal 有没有办法在 pycharm 的终端中自动执行一个程序来填写命令? - Is there a way to automate a program to fill in commands in the terminal on pycharm? Spinner 程序在 Pycharm IDE 中执行,但不在 zsh 终端中执行 - Spinner program exectues in Pycharm IDE but not in zsh terminal Python 脚本在 PyCharm 中无法正确运行,但在终端中运行 - Python script doesn't run correctly in PyCharm but runs in terminal 无法在PyCharm中导入MySQLdb,在终端上运行良好。 - Cannot Import MySQLdb in PyCharm, runs fine in terminal. 标准Python名称在PyCharm中标记为未解析,但程序运行成功 - Standard Python names are flagged as unresolved in PyCharm, but the program runs successfully 程序在Pycharm和IDLE下运行,直接打开就崩溃 - Program runs in Pycharm and IDLE, but crashes when opened directly 从Teminal运行python程序时出错,但在Pycharm中运行良好 - Error running python program from Teminal but it runs fine in Pycharm 如何使用 PyCharm CE 中的程序在终端中自动输入密码? - How to automatically enter the password in your terminal using a program in PyCharm CE? 程序在pycharm中完美运行,在终端中运行时给出错误答案 - Program run perfectly in pycharm, gives incorrect answer when run in terminal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM