首页 > 解决方案 > 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.

标签: pythondjangoubuntudjango-admin

解决方案


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 中的新功能。


推荐阅读