当我在heroku中部署django应用程序时,我运行:
heroku run python3 manage.py migrate
我在控制台上看到了这个消息:
File "manage.py", line 16
) from exc
^
SyntaxError: invalid syntax
我的manage.py文件实际上是:
#!~/.virtualenvs/djangodev/bin/python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myApp3.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
当我运行python=>python3,显示下一条消息:
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 16, in main
) from exc
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
您需要首先设置一个虚拟环境。然后在虚拟环境中安装django。你可以通过一个叫做pipenv
的东西来做到这一点。您需要通过执行将其添加到您的项目中。CCD_ 2。然后通过执行pipenv install django
在该虚拟环境中安装python。当django安装后,您就可以进行迁移了。