我已經閱讀過文檔,但我仍然無法完全理解Python如何處理導入。我得到以下錯誤:Python導入錯誤:沒有名爲Flask.myMethod的模塊
我已經檢查過的圓形進口(SERV進口class_definitions:from class_definitions import *
以及其他一些典型的Python模塊)class_definitions.py
只有進口泡菜 我試圖重建VENV 我鞏固代碼這兩個文件試圖讓它消失。
我在調試中取得的最大進展是,如果我擺脫了在class_definitions.py
中定義的函數調用load_pumps()
,它通常會消失。我可以將函數調用替換爲一組代表數據load_pumps()應該返回的虛擬數據,我不會得到這個錯誤。 load_pumps
在整個serv.py
的代碼的其他部分被調用,直到今天早些時候我才知道這個錯誤。有任何想法嗎?
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pi/Desktop/barbot/flask-files/serv.py", line 89, in admin
pump_list=load_pumps(),
File "/home/pi/Desktop/barbot/flask-files/class_definitions.py", line 90, in load_pumps
read_pump_list = pickle.load(file_pump)
File "/usr/lib/python2.7/pickle.py", line 1378, in load
return Unpickler(file).load()
File "/usr/lib/python2.7/pickle.py", line 858, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 1090, in load_global
klass = self.find_class(module, name)
File "/usr/lib/python2.7/pickle.py", line 1124, in find_class
__import__(module)
ImportError: No module named Flask.class_definitions
和文件樹是這個樣子
âââ admin_config.cfg
âââ class_definitions.py
âââ class_definitions.pyc
âââ __init__.py
âââ __init__.pyc
âââ lists
â  âââ bac_list.py
â  âââ bac_list.pyc
â  âââ cocktails_all.py
â  âââ cocktails_all.pyc
â  âââ garnishes_all.lst
â  âââ garnishes_selected.lst
â  âââ __init__.py
â  âââ __init__.pyc
â  âââ mixers_all.lst
â  âââ pumps.cfg
â  âââ spirits_all.lst
âââ requirements.txt
âââ serv.py
âââ serv.pyc
âââ templates
âââ admin_console.html
2 directories, 20 files
你的'PYTHONPATH'('print sys.path')是什麼? – zvone
我得看看鹹菜的文檔。我一直在虛擬機上開發,並決定將開發工作轉移到目標平臺上。所以絕對路徑改變了,但不是相對的。 –