【发布时间】:2014-09-10 17:27:38
【问题描述】:
我有以下目录结构
/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 函数,我需要调用 Generate_cert 函数,但是我无法导入模块。
我在 /opt/juno、/opt/juno/lib、/opt/juno/tests/、/opt/juno/tests/acceptance/、/opt/juno/tests/acceptance、/opt 中创建了 __init__.py /juno/tests/acceptance/cli-tests/,/opt/juno/tests/acceptance/cli-tests/cert-cli,目录。
关于如何在 test1.py 中调用 generate_cert 函数的任何帮助?
我在下面试过
[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" for 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
【问题讨论】:
标签: python module package python-import