简体   繁体   English

django-admin 启动项目错误(版本冲突?)

[英]django-admin startproject error (version conflict?)

When I run "django-admin startproject myproject" I get the following error: Traceback (most recent call last): File "/System/Volumes/Data/Library/Frameworks/Python.framework/Versions/3.11/bin/django-admin", line 5, in from django.core.management import execute_from_command_line File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/ init .py", line 17, in from django.conf import settings File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/conf/ init .py", line 14, in from pathlib import Path File "/opt/anaconda3/lib/python3.9/site-packages/pathlib.py", line 10, in from collections import Sequence ImportError: cannot import name 'Sequence' from 'collections' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/collections/ init .py)当我运行“django-admin startproject myproject”时,出现以下错误:Traceback(最后一次调用):文件“/System/Volumes/Data/Library/Frameworks/Python.framework/Versions/3.11/bin/django-admin ", 第 5 行,在 from django.core.management import execute_from_command_line 文件 "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/init.py",第 17 行,从django.conf导入设置文件“/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/conf/init.py”,第 14 行,从 pathlib导入路径文件“/opt/anaconda3/lib/python3.9/site-packages/pathlib.py”,第 10 行,来自 collections import Sequence ImportError:无法从“collections”(/Library/Frameworks/ Python.framework/Versions/3.11/lib/python3.11/collections/ init.py )

I'm assuming the problem is due to problems involving multiple locations and versions.我假设问题是由于涉及多个位置和版本的问题引起的。 Does that seem to be the correct assumption?这似乎是正确的假设吗? Suggestions for how to fix this?有关如何解决此问题的建议?

You've guessed it right I think, there's multiple versions of python you have, the mistake here is that you should've created a virtual env for python inside your Django project then activate it.我想你猜对了,你有多个版本的 python,这里的错误是你应该在你的 Django 项目中为 python 创建一个虚拟环境然后激活它。

  1. Open a terminal and navigate to the directory where you want to create your virtual environment.打开终端并导航到要创建虚拟环境的目录。
  2. Run the following command to create a new virtual environment: python3 -m venv myenv运行以下命令创建一个新的虚拟环境: python3 -m venv myenv
  3. Activate the virtual environment by running the following command: source myenv/bin/activate通过运行以下命令激活虚拟环境: source myenv/bin/activate
  4. Install Django in the virtual environment by running the following command: pip install django通过运行以下命令在虚拟环境中安装 Django: pip install django
  5. Run the django-admin startproject command to create your Django project.运行django-admin startproject命令以创建您的 Django 项目。 This should allow you to create your Django project without any conflicts.这应该允许您在没有任何冲突的情况下创建 Django 项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM