问题描述
我有一个python脚本,可以在pycharm终端内成功运行,设置为虚拟环境,但不能从Windows终端运行.我尚未设置任何Windows环境变量.
I have a python script that runs succesfully from within pycharm terminal, setup as a virtual enviroment, but not from the windows terminal. I haven't set any windows enviroment variables.
当脚本加载外部文本文件时,Python抛出 FileNotFoundError
.
Python is throwing FileNotFoundError
when the script is loading external text files.
我遇到了以下线程:在以下位置运行的脚本PyCharm,但不是从命令行,而且我认为从Windows终端运行时工作目录不正确.
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? and how do i fix it?
推荐答案
默认情况下,PyCharm的当前目录指向您的PyCharm沙箱的路径.如果您在此处放置了任何文件,它们将在PyCharm中加载而不会出现任何问题.
By default, PyCharm's current directory refers to the path to your PyCharm sandbox. If you've placed any files there, they'll load without any issues in 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.
这篇关于Python脚本可在PyCharm中使用,但会在Windows cmd中引发路径错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!