-1

I have a folder /example which contains /Libs which further contains different folders /a, /b each containing python libraries. I am trying to run a robot framework code from /example.

The error it shows :

Importing test library 'a' failed: ImportError: No module named 'a' File "/root/Libs/a/init.py", line 7, in from a import a_classname

How can I solve this?

Nafeez Quraishi
  • 5,380
  • 2
  • 27
  • 34
New_to_work
  • 253
  • 2
  • 5
  • 16
  • I have provided a path to /Libs into PYTHONPATH. – New_to_work Jul 18 '19 at 09:50
  • Please share your code which you have tried till now. – PySaad Jul 18 '19 at 09:52
  • @ComplicatedPhenomenon As far, I know in python-2.7 we never write .py while import. – PySaad Jul 18 '19 at 09:55
  • adding "--pythonpath /root/Libs/a " to my robot command helped me to import 'a'. But I have many libraries to import and can't afford to make robot command so lengthy. Is there any way to directly add these paths to PYTHONPATH? – New_to_work Jul 18 '19 at 10:13
  • 1
    Possible duplicate of [How to import other Python files?](https://stackoverflow.com/questions/2349991/how-to-import-other-python-files) – norok2 Jul 18 '19 at 10:34

1 Answers1

1
import os
import sys
filepath = "path/file/"
sys.path.append(os.path.abspath(filepath))
from a import a_classname
ComplicatedPhenomenon
  • 4,055
  • 2
  • 18
  • 45