Importing module from outside of the current directory - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Importing module from outside of the current directory (/thread-2453.html) |
Importing module from outside of the current directory - Annie - Mar-17-2017 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.hIt 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 ? RE: Importing module from outside of the current directory - snippsat - Mar-17-2017 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.
RE: Importing module from outside of the current directory - Annie - Mar-19-2017 Thank you, yeah, of course it's not possible...directly. There is something I didn't set up correctly. RE: Importing module from outside of the current directory - metulburr - Mar-19-2017 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-C-extensions-Part-1 RE: Importing module from outside of the current directory - Annie - Mar-21-2017 Thank you, I believe that is a program. I think there is a way to set up that in the package I'm using. |