[英]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.