我試圖用導入錯誤:沒有模塊名爲Django的,sys.path的罰款
python manage.py shell
配置Django和我得到的錯誤:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/lib64/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib64/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib64/python2.7/site-packages/django/apps/config.py", line 123, in create
import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named django
我已經看到了很多的問題,關於這個錯誤,其中大部分似乎都集中在python的sys.path中沒有包含django路徑的事實上。不過,我的是。當我運行
sudo pip install django
我得到
Requirement already satisfied: django in /usr/lib64/python2.7/site-packages
和輸出爲我的sys.path是
['', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages']
所以路徑是絕對有。 這裏有什麼我的選擇?這是一個使用來自Pycharm的SSH的遠程解釋器,它嚴重延遲了我的工作。
安裝django時是否使用虛擬env? –
我沒有,我對虛擬環境相對陌生。當虛擬機上只存在一個python版本時,是否有任何理由使用它? –
https://virtualenvwrapper.readthedocs.io/en/latest/ – PetarP