user7258733
user7258733

Reputation: 11

Python : Importing my custom script in Spyder to use with another script

Hello everyone I am learning Python. While using Spyder I finished writing my own function (test.py) I saved the script in a new folder. In Spyder I made sure to change my working directory to where the test.py is located as well as the PYTHON PATH. Now when I try to import test it says in the console that there are no modules named 'test'. Any help will be appreciated thank you

Upvotes: 0

Views: 1549

Answers (2)

user7258733
user7258733

Reputation: 11

Thank you Alex yeah the problem was I was not working in the same directory as the package I made so I opened up the command prompt in Spyder, went into the correct directory and was able to import/install it with no issues!!!

Upvotes: 1

Alex Lang
Alex Lang

Reputation: 180

have you tried

import sys
sys.path.append('path/to/test.py')
import test

if you want to import test inside of another script, the most sure-fire method is to just have both scripts in the same directory

Upvotes: 0

Related Questions