首页 \ 问答 \ PyCharm Python控制台中的文件路径错误(File path wrong in PyCharm Python Console)

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?

更新时间:2023-02-03 17:02

最满意答案

使用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 ...
  • 解决方案是: 从控制台运行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 ...
  • 进入设置 - >项目设置 - >项目解释器。 然后按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 ...
  • 我通过运行以下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 ...
  • 这就是你的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,关闭所有文件,并为新项目选择文件夹而不是文件来解决此问题。 解决方案受工作目录错误启发。 这也让我可以从令人沮丧的众多可用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.

相关文章

更多

最新问答

更多
  • 在csproj中使用appdata环境变量(Use appdata environment variable in csproj)
  • 从背景返回后,Skobbler Map崩溃(Skobbler Map crashes after returning from background)
  • 如何保持对绑定服务的轮询?(How to keep polling a bound service?)
  • ASP.NET单选按钮jQuery处理(ASP.NET radio button jQuery handling)
  • Linux上的FORTRAN图形库(FORTRAN graphic library on Linux)
  • 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))
  • 功能包装避免重复(wrap of functions avoid duplicating)
  • Android BroadcastReceiver和Activity.onPause()(Android BroadcastReceiver and Activity.onPause())
  • 无法使用phonegap 2.4在Android上播放录音(unable to play audio recordings on android using phonegap 2.4)
  • VS2015 + Resharper:不要使用C#6(VS2015 + Resharper: Don't use C#6)
  • 大学电脑四级对初学者来说要多久能过
  • 特殊字符删除?(Special characters remove?)
  • Android视频教程现在网上的都比较零散呢?有些太坑爹了,感觉老师就是在想当然的讲
  • 计算同一个表中不同行之间的差异[重复](Calculate delta's between different rows in same table [duplicate])
  • Javaweb开发,技术路线是什么?该怎么写?
  • JavaScript只在php代码中执行一次(JavaScript only executes once inside php code)
  • 不兼容的字符编码:ASCII-8BIT和UTF-8(incompatible character encodings: ASCII-8BIT and UTF-8)
  • Clojure(加载文件)给出错误(Clojure (load-file) gives an error)
  • 为具有瞬态scala依赖性的spring-xd项目优化gradle(Optimize gradle for spring-xd project with transient scala dependency)
  • 如何才能在Alpha测试模式下发布我的应用程序?(How can I publish my app in Alpha test mode only?)
  • “没有为此目标安装系统映像”Xamarin AVD Manager(“No system images installed for this target” Xamarin AVD Manager)
  • maven中的Scalatest:JUnit结果(Scalatest in maven: JUnit results)
  • 使用android SDK将文件直接上传到存储桶中的文件夹(Upload a file directly to a folder in bucket using android SDK)
  • 是否应将plists导入CoreData?(Should plists be imported to CoreData?)
  • java.lang.reflect.InvocationTargetException JavaFX TableView(java.lang.reflect.InvocationTargetException JavaFX TableView)
  • 根据唯一列值动态创建多个子集(Dynamically create multiple subsets based on unique column values)
  • 使用CSS可以使HTML锚标签不可点击/可链接吗?(Is it possible to make an HTML anchor tag not clickable/linkable using CSS?)
  • 嵌套的模板可能性(Nested template possibilities)
  • 任何方式在iOS7 +上以编程方式打开蓝牙(Any way to turn on bluetooth programmatically on iOS7+)
  • 如何为给定的SQL查询编写JPA查询(How I can write JPA query for given SQL query)