简体   繁体   English

Python脚本可在PyCharm中运行,但会在Windows cmd中引发路径错误

[英]Python script works in PyCharm but throws path errors in windows cmd

I have a python script that runs succesfully from within pycharm terminal, setup as a virtual enviroment, but not from the windows terminal. 我有一个从pycharm终端成功运行的python脚本,设置为虚拟环境,但没有从Windows终端运行。 I haven't set any windows enviroment variables. 我还没有设置任何Windows环境变量。

Python is throwing FileNotFoundError when the script is loading external text files. 当脚本加载外部文本文件时,Python抛出FileNotFoundError

I came across this thread: Script running in PyCharm but not from the command line and i think the working directory is not correct when running from the windows terminal. 我遇到了这个线程: 脚本在PyCharm中运行,但不是从命令行运行 ,我认为从Windows终端运行时工作目录不正确。

I do not understand the discrepancy. 我不明白这个差异。 What does Pycharm different than the windows terminal? Pycharm与Windows终端有什么不同? and how do i fix it? 以及我该如何解决?

By default, PyCharm's current directory refers to the path to your PyCharm sandbox. 默认情况下,PyCharm的当前目录指向您的PyCharm沙箱的路径。 If you've placed any files there, they'll load without any issues in PyCharm. 如果您在其中放置了任何文件,它们将在PyCharm中加载而不会出现任何问题。

From the command line, however, you'll either need to specify a fully qualified path (to where those files actually are), or you'd need to move them to the directory from where you run your script. 但是,从命令行中,您将需要指定一个完全限定的路径(这些文件的实际位置),或者需要将它们移动到运行脚本的目录中。

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

相关问题 Python脚本在pm2中抛出模块未找到错误但在cmd中有效 - Python script throws module not found error in pm2 but works in cmd 导入 python 模块在 cmd 中有效,但在 IDE (pycharm) 中无效 - Importing a python module works in cmd but not in an IDE (pycharm) 从cmd而非Windows调用Python脚本时有效 - Python script works when called from cmd but not via Windows Python 脚本在 PyCharm 中有效,但在终端中无效 - Python script works in PyCharm but not in terminal Python脚本在Windows命令行中抛出WindowsError,适用于Git Bash - Python script throws WindowsError in the Windows command line, works in Git Bash 模块适用于 cmd 但不适用于 Pycharm - Module works in cmd but not in Pycharm Python 标准输入错误,从 pycharm 复制的代码在 CMD 中不起作用 - Python stdin errors, copied code from pycharm wont work in CMD 适用于外语的python中的Windows CMD行错误 - Windows CMD line errors in python for foreign language Python 脚本工作但抛出错误 - pandas.errors 标记数据,预期 9 个字段看到 10 个 - Python script works but throws error - pandas.errors tokenizing data , Expected 9 fields saw 10 Python 脚本在 CMD 中不起作用,但可以用作 Jupyter Notebook - Python Script not working in CMD, but works as a Jupyter Notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM