PyCharm Python控制台中的文件路径错误(File path wrong in PyCharm Python Console)
我是Python的初学者,我想在PyCharm Python控制台中运行python3脚本,但是它在下面引发了一个错误:
>>> /Users/mymac/Documents/Python/test.py File "<input>", line1 /Users/mymac/Documents/Python/test.py ^ SyntaxError: invalid syntax
我不知道文件路径有什么问题,我该如何解决这个问题?
I'm a beginner of Python and I want to run a python3 script in PyCharm Python Console, but it raise an error below:
>>> /Users/mymac/Documents/Python/test.py File "<input>", line1 /Users/mymac/Documents/Python/test.py ^ SyntaxError: invalid syntax
I don't know what's wrong the file path is, how can I solve the problem?
最满意答案
使用
execfile('/Users/mymac/Documents/Python/test.py')
。 你正试图运行一个像可执行文件一样的python文件。 最重要的是,你正在使用python解释器。使用python的execfile例程来从解释器调用文件,或使用
python test.py
从终端运行它。use
execfile('/Users/mymac/Documents/Python/test.py')
. You are trying to run a python file like an executable. On top of that you are doing it in python interpreter.Use python's execfile routine to call a file from interpreter or use
python test.py
to run it from the terminal.
相关问答
更多-
使用execfile('/Users/mymac/Documents/Python/test.py') 。 你正试图运行一个像可执行文件一样的python文件。 最重要的是,你正在使用python解释器。 使用python的execfile例程来从解释器调用文件,或使用python test.py从终端运行它。 use execfile('/Users/mymac/Documents/Python/test.py'). You are trying to run a python file like an ...
-
Tensorflow和Pycharm(Tensorflow and Pycharm)[2022-02-15]
解决方案是: 从控制台运行PyCharm。 要么 将环境变量添加到IDE设置:LD_LIBRARY_PATH = / usr / local / cuda / lib64:$ LD_LIBRARY_PATH The solution is: Run PyCharm from the console. OR add the environment variable to the IDE settings: LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PA ... -
SQLAlchemy与Pycharm 4(SQLAlchemy with Pycharm 4)[2022-02-01]
进入设置 - >项目设置 - >项目解释器。 然后按configure interpreter,导航到“Paths”选项卡。 按“路径”区域中的+按钮。 您可以将路径放到您希望识别的模块中。 Go into Settings -> Project Settings -> Project Interpreter. Then press configure interpreter, and navigate to the "Paths" tab. Press the + button in the Paths ... -
在PyCharm python控制台中复制scrapy shell功能(Replicate scrapy shell abilities in PyCharm python console)[2022-12-15]
我通过运行以下python片段来实现它: from scrapy.cmdline import execute import sys sys.argv = ['scrapy', 'shell', 'http://scrapy.org'] execute() 如果您收到以下错误: MultipleInstanceError: Multiple incompatible subclass instances of InteractiveShellEmbed are being created. 那么你必须在 ... -
import cairosvg而不是import CairoSVG应该解决您的问题,来源: http : import CairoSVG import cairosvg instead of import CairoSVGshould fix your problem, source : http://cairosvg.org/
-
( Spyder维护者在这里 )为了避免Spyder中的这个问题,我们一次只允许在控制台中显示500行( 注意 :此限制可由用户配置) 所以我会说Pycharm的控制台没有这个功能(虽然我无法确定)。 (Spyder maintainer here) To avoid this problem in Spyder we only allow 500 lines to be shown in the console at a time (Note: This limit is configurable by ...
-
Pycharm - Python控制台(Pycharm - Python Console)[2022-05-30]
这就是你的pydev_import_hook.py应该是这样的: import sys from _pydevd_bundle.pydevd_constants import dict_contains from types import ModuleType class ImportHookManager(ModuleType): def __init__(self, name, system_import): ModuleType.__init__(self, name) ... -
Pycharm控制台是空白的(Pycharm console is blank)[2022-03-15]
通过重新启动Pycharm,关闭所有文件,并为新项目选择文件夹而不是文件来解决此问题。 解决方案受工作目录错误启发。 这也让我可以从令人沮丧的众多可用Python安装中访问正确的一个。 This issue was solved by re-starting Pycharm, closing all files, and choosing a folder, rather than a file, for a new project. Solution inspired by Working directo ... -
我遇到了同样的问题,我通过检查新项目的设置(在更高版本的PyCharm中创建)找到了解决方案。 将以下代码放在Django Console设置中(设置>构建,执行,部署>控制台> Django控制台>启动脚本): import sys; print('Python %s on %s' % (sys.version, sys.platform)) import django; print('Django %s' % django.get_version()) sys.path.extend([WORKING_ ...
-
JetBrains说,“不幸的是,没有鼠标就无法滚动控制台输出。” 我提交了一个增强请求,在Python控制台中添加键盘滚动 。 JetBrains says, "Unfortunately it's not possible to scroll console output without mouse." I filed an enhancement request to add keyboard scrolling in the Python console.