Unable to import python modules from different directories -


i have below directory structure

/opt/juno/ +/opt/juno/__init__.py  +/opt/juno/lib/__init__.py +/opt/juno/lib/gen_cert_request.py-class certdb->def generate_cert() +/opt/juno/tests/acceptance/cli_tests/cert-cli/test1.py 

test1.py pytest functions, need call generate_cert function , unable import modules.

i created __init__.py in /opt/juno, /opt/juno/lib, /opt/juno/tests/, /opt/juno/tests/acceptance/, /opt/juno/tests/acceptance, /opt/juno/tests/acceptance/cli-tests/, /opt/juno/tests/acceptance/cli-tests/cert-cli, directory.

any on how can call generate_cert function in test1.py ?

i tried below

[root@pkiserver1 pki-cert-cli]# pwd /opt/juno/tests/acceptance/cli-tests/pki-cert-cli [root@pkiserver1 pki-cert-cli]# ls -l /opt/juno/lib/ total 48 -rw-r--r--. 1 root root 5355 sep 10 13:13 gen_cert_request.py -rw-r--r--. 1 root root 5772 sep 10 13:14 gen_cert_request.pyc -rw-r--r--. 1 root root    0 sep 10 13:08 __init__.py -rw-r--r--. 1 root root  102 sep 10 13:14 __init__.pyc -rw-r--r--. 1 root root 4507 sep 10 03:41 pki-wrapping-data.py -rw-r--r--. 1 root root 1750 sep 10 07:28 profile-xml.py -rw-r--r--. 1 root root   29 sep  9 09:22 readme.md -rw-r--r--. 1 root root  677 sep 10 07:57 run_pki_commands.py -rw-r--r--. 1 root root  941 sep 10 12:05 run_pki_commands.pyc  drwxr-xr-x. 2 root root 4096 sep 10 12:40 tests   [root@pkiserver1 pki-cert-cli]# python  python 2.7.5 (default, jun 25 2014, 10:19:55)   [gcc 4.8.2 20131212 (red hat 4.8.2-7)] on linux2  type "help", "copyright", "credits" or "license" more information.  >>> import juno.lib.gen_cert_request  traceback (most recent call last):  file "<stdin>", line 1, in <module>  importerror: no module named juno.lib.gen_cert_request  >>> import lib.gen_cert_request  traceback (most recent call last):  file "<stdin>", line 1, in <module>  importerror: no module named lib.gen_cert_request 

you need tell interpreter custom search path module files. can pass either environment variable pythonpath or modify sys.path program, e.g.:

import sys sys.path.append('/tmp/juno') lib.gen_cert_request import certdb 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -