0

I am trying to import a python file from another directory in my current working python file as shown below snapshot. I would appreciate if you guys can share how to achieve it.

enter image description here

In dashboard.py I tried :

import sys
sys.path.append('/home/lungsang/Desktop/streamlit-practice/level-packs')
import usage.py

usage.py is in level-packs directory.

as of now its not working..

lungsang
  • 133
  • 13

2 Answers2

1

try replacing

import sys
sys.path.append('/home/lungsang/Desktop/streamlit-practice/level-packs')
import usage.py

by

import sys
sys.path.append("levelpacks") # or sys.path.append("/home/lungsang/Desktop/streamlit-practice/levelpacks")
import levelpacks.usage as usage

the "-" seems to be an issue, you need to change your folder name

About your last edit:

The usage.py file is not directly in your levelpacks folder

So you need to do

import sys
sys.path.append("levelpacks") # or sys.path.append("/home/lungsang/Desktop/streamlit-practice/levelpacks")
import levelpacks.level_packs.usage as usage
YfNk
  • 94
  • 5
0
def levelpack_ui():
    from levelpacks.level_packs import create_packs
    create_packs()

After applying above method, it's working fine. thank you :)

lungsang
  • 133
  • 13