简体   繁体   English

在 Spyder 中,如何从另一个脚本的项目文件夹中运行 python 脚本

[英]In Spyder how do you run a python script in the projects folder from another script

I am wondering how I can run/load a python script containing all the imports needed and functions for the main script from the main script.我想知道如何运行/加载 python 脚本,其中包含主脚本所需的所有导入和主脚本的功能。 I cant figure out how to do it, runfile works in the console but not the script itself.我不知道该怎么做,runfile 在控制台中工作,而不是脚本本身。 When I try stuff like that is just says runfile is undefined.当我尝试这样的事情时,只是说运行文件未定义。

截屏

You can save a python file to here: C:\ProgramData\Anaconda3\Lib (Or where ever your python is) called "mysetup.py" and have the contents of the file as the import commands that you want like this.您可以将一个名为“mysetup.py”的文件名为“mysetup.py”的文件保存到此处:

在此处输入图像描述

Then in your other python file you can can import the name of your file like this然后在您的其他 python 文件中,您可以像这样导入文件的名称

import mysetup

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM