[英]Python: “bad interpreter: No such file or directory” when running django-admin.py
I've googled the hell out of this, but all of the solutions I've found seem to solve problems that are not mine.我已经用谷歌搜索了这个地狱,但我找到的所有解决方案似乎都解决了不属于我的问题。
I created a project in a virtual environment in /Users/[user]/Documents/projects/[project]
using virtualenv
and installed Django.我使用virtualenv
在/Users/[user]/Documents/projects/[project]
的虚拟环境中创建了一个项目并安装了 Django。
Later, I deleted that project and installed Django on my system outside of the virtual environment.后来,我删除了该项目,并在虚拟环境之外的系统上安装了 Django。 Now, I am trying to run this:现在,我试图运行这个:
django-admin.py startproject mysite
However, I am receiving this error message:但是,我收到此错误消息:
-bash: /usr/local/bin/django-admin.py:
/Users/[user]/Documents/projects/[project]/bin/python:
bad interpreter: No such file or directory
I have found that the only way I can make this work again is by setting up the [project] virtual environment as I had it before with Django installed in it.我发现我可以再次使这项工作的唯一方法是设置 [project] 虚拟环境,就像我之前安装的 Django 一样。
How do I fix this?我该如何解决?
I'm not sure what you did to produce this error, but the fix for you is to change /usr/local/bin/django-admin.py
shebang to #!/usr/bin/env python
.我不确定你做了什么导致这个错误,但你的解决方法是将/usr/local/bin/django-admin.py
shebang更改为#!/usr/bin/env python
。
Actually if you install django in a virtualenv, the django-admin.py
will have the shebang set to the python interpreter of your virtualenv, but this script will not be created in /usr/local/bin/
.实际上,如果您在 virtualenv 中安装 django, django-admin.py
会将 shebang 设置为您的 virtualenv 的 python 解释器,但不会在/usr/local/bin/
创建此脚本。
Instead this script will be created in /<virtualenvpath>/bin/
along with activate
and the virtualenv python interpreter.相反,此脚本将在/<virtualenvpath>/bin/
与activate
和 virtualenv python 解释器一起创建。 You should then move this script to /usr/local/bin/
.然后,您应该将此脚本移动到/usr/local/bin/
。
For me, It was that the last program or script that i invoked didn't correctly end .对我来说,这是我调用的最后一个程序或脚本没有正确结束。 In that case (base) marks in front of your command when you are using the terminal[mac].在这种情况下,当您使用终端 [mac] 时,在您的命令前面标记(base) 。
To deactivate the environment,要停用环境,
source deactivate
OR // if using conda或 // 如果使用 conda
conda deactivate
This error can occur when you move your project to a different directory, for example, if your former directory was: /Users/theuser/complete-ml-ds/sample_project/env/bin/python3-config then it has to be updated to the new directory at the very top of python3-config file当您将项目移动到其他目录时可能会发生此错误,例如,如果您以前的目录是:/Users/theuser/complete-ml-ds/sample_project/env/bin/python3-config 那么它必须更新为python3-config 文件最顶部的新目录
Update the directory information:更新目录信息:
with your new directory使用您的新目录
For django latest version use对于 django 最新版本使用
django-admin startproject mysite
This works for me.这对我有用。
change my to your project name.将 my 更改为您的项目名称。 No need to use django-admin.py use django-admin only.不需要使用 django-admin.py 只使用 django-admin。 Activate your environment.激活您的环境。 Then use the above comment.然后使用上面的注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.