简体   繁体   English

Python 脚本在 CMD 中不起作用,但可以用作 Jupyter Notebook

[英]Python Script not working in CMD, but works as a Jupyter Notebook

I'd like to get a little insight for this issue I'm running into.我想对我遇到的这个问题有所了解。 I'm a rookie when it comes to python, and I'm not even sure how to properly identify my issue so I can research better answers.我是 python 的新手,我什至不确定如何正确识别我的问题,以便我可以研究更好的答案。

I'm using windows 10, and running python 3.8 (same issues arose with 3.7, before I did a clean install)我正在使用 windows 10,并运行 python 3.8(在我进行全新安装之前,3.7 也出现了同样的问题)

I've written an API call in Jupyter and after a week of struggling, I finally got it to execute and save the data into a nice csv into a folder on my hard drive.我在 Jupyter 中编写了一个 API 调用,经过一周的努力,我终于让它执行并将数据保存到一个不错的 csv 到我硬盘上的文件夹中。 I saved the code as a.py.我将代码保存为 a.py。 My next step was to automate this API call by using Windows Task Scheduler for everyday 2pm to run the.py script from the command line.我的下一步是通过在每天下午 2 点使用 Windows 任务计划程序来自动化这个 API 调用,以从命令行运行 .py 脚本。

I noticed it wasnt running, and tried to run it manually, but all that happens is a command prompt opens and closes faster than I can see whats going on.我注意到它没有运行,并尝试手动运行它,但所发生的只是命令提示符打开和关闭的速度比我看到的要快。 There is no output in the destination folder.目标文件夹中没有 output。

I wanted to make sure python was correctly installed, and set to PATH, and after double checking everything I got a successful 'Hello World' printed from the command line just fine.我想确保 python 已正确安装,并设置为 PATH,在仔细检查所有内容后,我从命令行成功打印了“Hello World”。 But when I try to run the.py script all it does is return the name of the script I am trying to run, with no error or kickback message.但是当我尝试运行 .py 脚本时,它所做的只是返回我尝试运行的脚本的名称,没有错误或回扣消息。 I'm not sure where things are going wrong.我不确定哪里出了问题。

To further complicate things, I am unable to get this code to run in Visual Studio.更复杂的是,我无法让这段代码在 Visual Studio 中运行。 To further further complicate things, I was worried these issues arose because I didn't have the necessary modules installed (such as pandas, or json).更复杂的是,我担心会出现这些问题,因为我没有安装必要的模块(例如 pandas 或 json)。 Attempts a pip install returned synatx errors.尝试 pip 安装返回 synatx 错误。

I apologize for the mess, and I'm sure my terminology is close enough just to be confusing.我为混乱道歉,我确信我的术语足够接近,只是为了混淆。 Any help, links to other questions, or ideas would be greatly appreciated.任何帮助、其他问题的链接或想法将不胜感激。

Dealing with the same damn thing right now.现在正在处理同样该死的事情。

from datetime import datetime, date
print("Your date of birth (dd mm yyyy)")
dateOfBirth = datetime.strptime(input("Enter your date of birth: "), "%d %m %Y")

def calculateAge(born):
    today = date.today()
    return today.year - born.year - ((today.month, today.day) < (born.month, born.day))

age = str(calculateAge(dateOfBirth))
print("You're " + age + " years old")

Let me know if you ever come across any solution.如果您遇到任何解决方案,请告诉我。 Note my code runs perfectly fine in jupyter notebook but not in the command line.请注意,我的代码在 jupyter notebook 中运行得非常好,但在命令行中却没有。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM