python - Cannot run django-admin.py startproject in virtual environment, or at all, in Ubuntu
问题描述
I am trying to create a project in a virtual environment in Ubuntu 16.04
I am using Python 3.6
What I do so far is
sudo bash
cd Desktop/DamLevels-course2/Damlevels2/
source venv2/bin/activate
django-admin.py startproject dams
The error says: ImportError: No module named 'secrets'
I have checked the list of modules in python and secrets is there, but when I try to import to the virtual environment I get an error saying : import: not authorized 'secrets' @ error/constitute.c/WriteImage/1028
I tried adding the shebang line as well (#!/usr/bin/env) but that didn't seem to work; running the startproject line again results in the same error message as before.
I am very new to all of this, so I would appreciate fairly simple help.
解决方案
Django 文档说明创建新项目的命令是:
$ django-admin startproject mysite
因此,要创建您的项目,请将“mysite”替换为“dams”,或者您的项目名称。例如:
$ django-admin startproject dams
此外,也许这是一个错字,但应该安装的包是“python3-django”,而不是“python-django”。此命令将安装 python3-django。
$ sudo apt-get install python3-django
Django 文档还提到了运行 django-admin 的潜在问题。这是一段提到 django-admin 和 django-admin.py 之间问题的摘录。
运行 django-admin 的问题
找不到命令:django-admin
如果您通过 pip 安装 Django, django-admin应该在您的系统路径中。如果它不在您的路径上,您可以在“site-packages/django/bin”中找到它,其中 site-packages 是 Python 安装中的一个目录。考虑从路径上的某个位置符号链接到django-admin,例如 /usr/local/bin。
如果django-admin不起作用但django-admin.py 起作用,那么您可能使用的 Django 版本与本文档的版本不匹配。django-admin是 Django 1.7 中的新功能。
推荐阅读
- python - Python合并csv文件问题处理和重复的单元格部分
- python - KeyError:“[索引([('A','B','C')],dtype ='object')]都没有在[列]中
- amazon-s3 - S3 / COS:使用 IBM Cloud 配置的 rclone 身份验证失败
- python - 不和谐.py | 我可以在命令名中有空格吗?
- html - 从 Express NodeJS 中的选中复选框中获取所有“名称”属性
- angular - 角表排序,没有角材料
- python - Python 正则表达式:从字符串中提取体积(mL)
- java - 在其他应用程序之上创建按钮并使用 OnClickListener 的服务
- c# - 在进行 WCF https 调用时,Flutter Web 出现“XMLHttpRequest”错误
- php - 在 FilesystemManager 中找不到 Laravel 8 Class League AwsS3Adapter