Python Forum

Full Version: Importing module from outside of the current directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

If I'm in say /home/a
and I want to import a module name "file.h"  in   /home/b/c/d
I tried :


import sys
sys.path.insert(0, '/home/b/c/d')
but when I did

import file.h
It still says no module named file.h,even though file.h is indeed in the /home/b/c/d directory ?

What did I miss?

Oh, I should add that this file is not a python file, is it possible to do this ?
sys.path search for files with suffix .py only.
Quote:Oh, I should add that this file is not a python file, is it possible to do this ?
You most explain what you trying do eg "i want call/run C code from Python".
Suffix .h is a header file for C.
Thank you, yeah, of course it's not possible...directly. There is something I didn't set up correctly.
What are you storing in file.h? If its just constant values you should use something like JSON or similar. 

If you really need to create a C extension you should check out a tutorial to do so
https://python-forum.io/Thread-Creating-...ons-Part-1
Thank you, I believe that is a program.
I think there is a way to set up that in the package I'm using.