我对Python比较陌生,已经开发了我公司的自动化框架。当我尝试通过解释器运行我的Python脚本时,为什么会出现“ImportError:No module named”?
在开发过程中,我第一次遇到了需要同时运行多个测试的情况。直到现在,我总是使用Eclipse,不仅开发我的框架,而且还运行测试(当然,它一次只有一个)。 当我试图通过CMD屏幕“python”运行我的一个测试(我设法通过Eclipse运行的一个测试)时,它甚至没有开始运行,我得到的结果是“ImportError:No module named”(有关到我从开发的软件包中进口的产品)。
Eclipse如何设法与我所有的Imports相处并运行我的测试,而python解释器不能?
为了通过解释器来运行我的测试,我需要做些什么?
编辑
下面举例说明什么,我为了试图导入我的私有模块
C:\Users\alpha_2.PL\workspace\PacketLight Automation\Test_Cases>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900
64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or
"license" for more information.
>>> from Utilities.Browser_Utils import Open_Browser Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError:
No module named 'Utilities'
>>> quit()
C:\Users\alpha_2.PL\workspace\PacketLight Automation\Test_Cases>cd..
C:\Users\alpha_2.PL\workspace\PacketLight Automation>cd Utilities
C:\Users\alpha_2.PL\workspace\PacketLight Automation\Utilities>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900
64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or
"license" for more information.
>>> from Utilities.Browser_Utils import Open_Browser Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError:
No module named 'Utilities'
>>> quit()
C:\Users\alpha_2.PL\workspace\PacketLight Automation\Utilities>dir
Volume in drive C has no label. Volume Serial Number is 1E0C-6554
Directory of C:\Users\alpha_2.PL\workspace\PacketLight Automation\Utilities
08/07/2017 03:05 PM <DIR> .
08/07/2017 03:05 PM <DIR> ..
08/10/2017 10:28 AM 455 Browser_Utils.py
09/05/2017 05:00 PM 7,007 General_Utils.py
07/31/2017 01:49 PM 0 __init__.py
09/05/2017 06:07 PM <DIR> __pycache__
3 File(s) 7,462 bytes
3 Dir(s) 394,707,480,576 bytes free
C:\Users\alpha_2.PL\workspace\PacketLight Automation\Utilities>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900
64 bit (AM D64)] on win32 Type "help", "copyright", "credits" or
"license" for more information.
>>> from Utilities.Browser_Utils import Open_Browser
Traceback (most recent call last):
File "<stdin>", line 1, in <module> ImportError:
No module named 'Utilities'
>>>
使用python3,而不是蟒蛇的人。否则你必须使用pip3来安装所有的python3软件包。 –
看起来您需要阅读一些有关Python环境的文章 - 对于学习在IDE中使用该语言的人来说,这几乎是不合适的。您可能会发现Eclipse会特别努力管理PYTHONPATH环境变量。 – holdenweb
@rabbit_mq什么是python3?你为什么认为它可以解决我的问题? –