Python Forum
How to import another Python in different directory?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to import another Python in different directory?
#1
Hello,
I would like to get help on importing another Python program in different directory. I didn't seem finding that is straight forward from googling.
Thanks.
Reply
#2
I figured it out. Thanks.

Sorry. I don't know how to delete the post.
Reply
#3
Instead of deleting the post, post your answer to the question. There might be a better way to solve this problem, or somebody else might have the same problem and would benefit from reading your solution.
buran likes this post
Reply
#4
Added the directory where the Python program is located to the sys.path, then import the Python program.

import sys
file_dir = "c:\\Users\\dee\\Documents\\_Python"
sys.path.append( file_dir )
import Connection as conn
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 2,334 Feb-02-2020, 08:46 PM
Last Post: snippsat
  wordpress-python-xmlrpc. I can import 1 file. How do I import the entire folder? SamLearnsPython 0 3,232 Jul-05-2018, 06:21 AM
Last Post: SamLearnsPython
  How to import a file from outside the directory sylas 5 6,631 May-10-2018, 07:19 AM
Last Post: Larz60+
  How to import dependencies from a different directory? ayunus 3 2,728 Feb-11-2018, 04:22 AM
Last Post: ayunus

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020