我對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?你爲什麼認爲它可以解決我的問題? –