Reputation: 133
The code for PyCharm to import the package extra
:
from sys import path
path.append('..\\packages')
import extra.iota
The same code in Visual Studio Code rises an error:
ModuleNotFoundError: No module named 'extra'
For some reason, to import the extra
module in Visual Studio Code I need to use this code:
from sys import path
path.append('.\\packages')
import extra.iota
Can somebody explain why do I need to use one dot instead of two dots in VSC?
Upvotes: 0
Views: 714
Reputation: 49
Get the pathfile by calling file
pathfile = os.path.join(os.path.dirname(file)) system.path.insert(0, os.path.abspath(pathfile))
Upvotes: 0
Reputation: 3346
You can insert complete path of package into sys.path.
you can get current path by __file__
check below code:
path = os.path.join(os.path.dirname(__file__), "../packages")
sys.path.insert(0, os.path.abspath(path))
Make sure you add absolute path of the package.
Sometimes the working directory is different in many IDE so its better to use complete path.
Upvotes: 1