I'm trying to run my tests, on my virtual environment, so when I run the command:
python server/manage.py test --settings=skillcorner.settings_test api
I get the following Error:
> File "server/manage.py", line 8
> print(f'Running with settings: {os.environ["DJANGO_SETTINGS_MODULE"]}')
> ^
> SyntaxError: invalid syntax
so I run (on my virtual environment) the command (I just used python3 instead of python:
python3 server/manage.py test --settings=skillcorner.settings_test api
I get the following error, which is the one I am stuck on:
> Running with settings: skillcorner.settings_local
> Traceback (most recent call last):
> File "server/manage.py", line 12, in <module>
> execute_from_command_line(sys.argv)
> File "/home/yosra/.local/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 381, in execute_from_command_line
> utility.execute()
> File "/home/yosra/.local/lib/python3.6/site-packages/django/core/management/__init__.py",
> line 357, in execute
> django.setup() File "/home/yosra/.local/lib/python3.6/site-packages/django/__init__.py",
> line 24, in setup
> apps.populate(settings.INSTALLED_APPS)
> File "/home/yosra/.local/lib/python3.6/site-packages/django/apps/registry.py",
> line 91, in populate
> app_config = AppConfig.create(entry)
> File "/home/yosra/.local/lib/python3.6/site-packages/django/apps/config.py",
> line 90, in create
> module = import_module(entry)
> File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
> File "<frozen importlib._bootstrap>", line 994, in _gcd_import
> File "<frozen importlib._bootstrap>", line 971, in _find_and_load
> File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
> ModuleNotFoundError: No module named 'rest_framework
I can't figure out how to fix this, I tried to install rest-framework using ppip install, but it doesn't work!
答案 0 :(得分:0)
我无法真正确定您如何管理虚拟环境,但是我很确定问题确实存在。我会假设以下内容:
f'{something}'
格式(因此在python2中引起了错误)rest_framework
。 我的建议:
deactivate
python3 -m venv venv
以创建新环境source venv/bin/activate
requirements.txt
或pip install django djangorestframework
安装您的依赖项(以及项目的任何其他依赖项)python manage.py whatevercommand
或./manage.py whatevercommand
(如果激活了环境,则两者都将运行python3)最后一个提示:您可以使用python --version