简体   繁体   English

django-admin.py未运行

[英]django-admin.py not running

I'll add another django-admin.py question, as none of the other questions seem to cover my issue: 我将添加另一个django-admin.py问题,因为其他任何问题似乎都无法解决我的问题:

I've installed django via pip: 我已经通过pip安装了django:

$ pip install django

My pip and Python versions are: 我的pip和Python版本是:

$ pip -V
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Specifically, python is version 2.7.14. 具体来说,python是2.7.14版。 At this point I expected to run 在这一点上,我希望能跑

$ django-admin startproject myTestProject

which would then create my project folders in the current directory. 然后会在当前目录中创建我的项目文件夹。

However, this returns 但是,这返回

Cannot find installed version of python-django or python3-django

This confuses me, since when I ran 这让我感到困惑,因为当我跑步时

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Further, I checked where the file django-admin.py is located: 此外,我检查了文件django-admin.py的位置:

$ find -iname "django-admin.py"
./.local/bin/django-admin.py
./.local/lib/python2.7/site-packages/django/bin/django-admin.py

So it seems like django-admin.py is in my PATH. 因此,似乎django-admin.py在我的PATH中。 Why then can I not run it? 为什么我不能运行它?

(extra info: I do have python 3.6.3 installed, too. But I don't think this version has anything to do with pip or django.) (额外信息:我也安装了python 3.6.3。但是我认为此版本与pip或django没有任何关系。)

I recommend you always use a virtual environment manager with your Django projects, such as virtualenvwrapper ( pip install virtualenvwrapper or sudo pip install virtualenvwrapper see here for installation instructions) 我建议您始终在Django项目中使用虚拟环境管理器,例如virtualenvwrapper( pip install virtualenvwrappersudo pip install virtualenvwrapper请参见此处以获取安装说明)

then you can mkvirtualenv myprojectname and install django into the virtual environment ( pip install django ). 然后您可以mkvirtualenv myprojectname并将django安装到虚拟环境中( pip install django )。 then you will not face any problems such as this 那么您将不会遇到任何此类问题

So, there are a few things, 所以,有几件事,

  1. You should be looking for django-admin not django-admin.py . 您应该在寻找django-admin而不是django-admin.py
  2. Your paths have /usr/local/bin , what you're looking at is /home/<your user>/.local which is certainly not the right place. 您的路径具有/usr/local/bin ,您正在查看的是/home/<your user>/.local ,这当然不是正确的位置。
  3. As everybody suggested, use virtualenv for maintaining your projects and its dependencies cleanly and nicely. 正如每个人所建议的那样,使用virtualenv可以很好地维护您的项目及其依赖项。

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

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