장고 가져 오기 오류-이름이 core.management 인 모듈이 없습니다.
좋아, 나는이 오류가 많이 보인다. 나는 내가 알고있는 모든 것을 시도했지만 아직 이것을 파악하지 못했습니다.
python 2.5 및 Django 1.3을 실행하는 개발 서버에서 작업하고 있습니다. Django 1.3은 tar.gz 다운로드를 압축 해제 한 후 python setup.py install을 사용하여 설치되었습니다.
모든 것이 잘 작동하지만 거의 실행할 필요가 manage.py
없지만 새로운 정적 파일 응용 프로그램을 사용하려고하는데 문제가 발생합니다.
python manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
좋아, 그래서 PATH
문제 가 있다.
Django 설치 에서 site-packages
디렉토리를 다시 확인하십시오 .
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
/usr/lib/python2.5/site-packages
좋아, 내가 가지고있는 것을 확인하고 echo $ PYTHON_PATH가 비어 있으므로 설정했습니다.
export PYTHON_PATH=/usr/lib/python2.5/site-packages/django
아직 운이 없다. sys.path가 무엇을 말해야하는지 확인하자
>>> import sys
>>> print sys.path
['', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/usr/lib/python2.5/site-packages/django', '/var/lib/python-support/python2.5']
경로가 있으며 내용으로 /usr/lib/python2.5/site-packages/django.pth도 만들었습니다.
cat /usr/lib/python2.5/site-packages/django.pth
/usr/lib/python2.5/site-packages/django/
아무도 여기에서 무슨 일이 일어나고 있는지 실마리를 얻었습니까?
나는 길을 가고있는 더 많은 심볼릭 링크를 찾았지만 새로운 오류는 없습니다.
python manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.5/site-packages/django/core/management/__init__.py", line 349, in execute
version=get_version(),
File "/usr/lib/python2.5/site-packages/django/__init__.py", line 12, in get_version
from django.utils.version import get_svn_revision
ImportError: No module named utils.version
또한 새 프로젝트를 만들어서 문제가 있는지 확인하고 동일한 utils.version 오류가 발생했습니다.
사이드 노드 : #django의 Unode는 저에게 약간의 도움을 주며 동일한 컴퓨터에 virtualenv를 설정하고 오류를 극복 했으므로 여전히 실제 설치에 어떤 문제가 있는지 확실하지 않지만 장고 프로젝트에는 없지만 장고에는있는 것 같습니다. / python 설치.
나처럼 virtualenv에서 django를 실행 하고이 오류가 발생하면를 참조하십시오 manage.py
. 첫 번째 줄은 스크립트를 실행하는 데 사용되는 python 실행 파일을 정의해야합니다. 이것은 virtualenv의 파이썬에 대한 경로 여야하지만 / usr / bin / python과 같은 경로는 아닙니다. 동일한 경로가 아니며 전역 파이썬 환경을 사용합니다 (패키지가 누락 될 수 있습니다). virtualenv의 python 실행 파일 경로로 경로를 변경하십시오.
shebang 줄을로 바꿀 수도 있습니다 #!/usr/bin/env python
. virtualenv를 먼저 활성화하면 적절한 파이썬 환경과 인터프리터를 사용해야합니다 (이 방법을 알고 있다고 가정합니다).
virtualenv에 있다면 ./manage.py 'command'를 실행하기 전에 활성화해야합니다.
source path/to/your/virtualenv/bin/activate
.bash_profile 또는 .bashrc에서 workon을 구성하는 경우
workon yourvirtualenvname
* manage.py 파일을 수정하지 마십시오. 아직 올바른 방법으로 작동하지 않으며 향후 오류가 발생할 수 있습니다
Django를 수퍼 유저로 설치했기 때문에 같은 문제가 있었으므로 virtualenv에는 없습니다. 해서는 안됩니다sudo pip install Django
대신 다음과 같이 설치하십시오.
$ source ./bin/activate
$ pip install Django
pip로 django를 다시 설치하십시오.
sudo pip install --upgrade django==1.3
(1.3을 장고 버전으로 교체하십시오)
알려진 바와 같이 이것은 경로 문제였습니다.
내 사용자 정의 패키지의 기본은 / etc / profile에 설정된 디렉토리와 이름을 공유했습니다. 그러나 패키지는 웹 서버와 다른 위치에있었습니다. 그래서 나는 $ PYTHONPATH에서 문제가되는 항목을 제거하고 갈 수있었습니다!
도와 주셔서 감사합니다.
이 문제의 또 다른 이유는 OS가 기본적으로 python3을 실행하기 때문입니다.
어느 쪽이든 명시 적으로 : python2 manage.py
또는 manage.py의 shebang을 다음과 같이 편집하십시오.
#!/usr/bin/env python2
I had this error while trying to run an embedded system (using django of course) on a Raspberry Pi 2 (and not a VM)
Running this:
sudo pip install Django
Made the trick!
- just in case a fellow using Raspbian/Jessie gets this
You are probably using virtualenvwrapper. Don't forget to select your enviroment by running:
$ workon env_name
For me, my server was using Python 2.4. I simply looked up Python 2.7, which was installed on my server, and created an alias.
alias python=python2.7
If you need to know more, I found the solution here
I was getting the same problem while I trying to create a new app. If you write python manage.py startapp myapp
, then it looks for usr/bin/python. But you need this "python" which is located in /bin directory of your virtual env path. I solved this by mentioning the virtualenv's python path just like this:
<env path>/bin/python manage.py startapp myapp
Try change your first line of manage.py.
Change
#!/usr/bin/python
by
#!/usr/bin/env python
Solved it!!!
After searching for ages and trying all these other suggestions which didn't work, I finally found the solution for my setup.
My setup/scenario:
- Windows, Python27
- My django project is checked out via svn
- when running python manage.py runserver in the new folder, I got the import error
- python manage.py runserver used to work in the original folder (which I would commit changes from) until I deleted it
Solution
Remove any the folder named django in the same directory of manage.py
Thats right...as soon as I removed the folder "django" which only contained a __init__.py file...I could run the server again!
Have no idea why though
For those of you using Django 1.6 or newer, note that execute_manager was removed. There is a solution posted in the second SO answer here.
Store the python python path in a variable and execute.This would include the otherwise missing packages.
python_path= `which python`
$python_path manage.py runserver
python3 manage.py runserver
Check version of Python
I had a similar problem. PyCharm couldn't run the server but I could run it from the command line. I tried which python and then made sure that PyCharm was same interpreter and then everything worked OK.
This error usually occurs when django is not installed. If you have already installed django but still getting the same error, then you must be working in separate virtual environment. You need to install django in your virtual environmnent as well. When you are in shell of virtual machine simply do this:
pip install django
It is because virtual machine has separate file system, it doesn't recognize django even if it is installed on your system.
I fixed this problem by changing #PATH="$VIRTUAL_ENV/bin:$PATH" to PATH="$PATH:$VIRTUAL_ENV/bin" For reasons not obvious to me the python executable in the virtualenv dir does not see django but the normally installed python does.
==================================SOLUTION=========================================
First goto: virtualenv
by running the command: source bin/activate
and install django because you are getting the error related to 'import django':
pip install django
Then run: python manage.py runserver
(Note: please change 'runserver' to the program name you want to run)
For the same issue, it worked in my case. ==================================Synopsis========================================= ERROR: (Development) Rakeshs-MacBook-Pro:src rakesh$ python manage.py runserver Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "manage.py", line 14, in import django ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "manage.py", line 17, in "Couldn't import Django. Are you sure it's installed and " ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? (Development) Rakeshs-MacBook-Pro:src rakesh$ (Development) Rakeshs-MacBook-Pro:src rakesh$ (Development) Rakeshs-MacBook-Pro:src rakesh$ python -Wall manage.py test Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "manage.py", line 14, in import django ModuleNotFoundError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "manage.py", line 17, in "Couldn't import Django. Are you sure it's installed and " ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
AFTER INSTALLATION of django:
(Development) MacBook-Pro:src rakesh$ pip install django Collecting django Downloading https://files.pythonhosted.org/packages/51/1a/e0ac7886c7123a03814178d7517dc822af0fe51a72e1a6bff26153103322/Django-2.1-py3-none-any.whl (7.3MB) 100% |████████████████████████████████| 7.3MB 1.1MB/s Collecting pytz (from django) Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB) 100% |████████████████████████████████| 512kB 4.7MB/s Installing collected packages: pytz, django
AFTER RESOLVING:
(Development) MacBook-Pro:src rakesh$ python manage.py runserver Performing system checks...
System check identified no issues (0 silenced).
You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.
August 05, 2018 - 04:39:02 Django version 2.1, using settings 'trydjango.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [05/Aug/2018 04:39:15] "GET / HTTP/1.1" 200 16348 [05/Aug/2018 04:39:15] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423 [05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564 [05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348 [05/Aug/2018 04:39:15] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304 Not Found: /favicon.ico [05/Aug/2018 04:39:16] "GET /favicon.ico HTTP/1.1" 404 1976
Good luck!!
your project is created using an old version of django-admin.py, older than django1.3
to fix this create another django project and copy its manage.py and paste it in the old one
Agreed completely that this is a path issue but fwiw, I had this same error. It was due to the mistake of using a relative path for my Python executable when setting up my virtual environment. I had done this:
virtualenv -p ~/python_runtimes/2.7.3/bin/python venv2.7.3 --distribute
Instead I had to give the full path to the Python executable.
HTH, Harlin
source ~/blog-venv/bin/activate
pick your virtualenv to replace "blog-venv" here.
Be sure you're running the right instance of Python with the right directories on the path. In my case, this error resulted from running the python
executable by accident - I had actually installed Django under the python2.7
framework & libraries. The same could happen as a result of virtualenv as well.
Okay so it goes like this:
You have created a virtual environment and django module belongs to that environment only.Since virtualenv isolates itself from everything else,hence you are seeing this.
go through this for further assistance:
1.You can switch to the directory where your virtual environment is stored and then run the django module.
2.Alternatively you can install django globally to your python->site-packages by either running pip or easy_install
Command using pip: pip install django
then do this:
import django print (django.get_version()) (depending on which version of python you use.This for python 3+ series)
and then you can run this: python manage.py runserver and check on your web browser by typing :localhost:8000 and you should see django powered page.
Hope this helps.
I included the name of the new App to the INSTALLED_APPS list in the settings.py "before" I issued the startapp command. Once I removed the list entry, I could create the app.
I solved this problem by using 'django-admin' command as following instead:
django-admin startproject _project_name
just remove the ".py" attached to "django-admin"
Having an application called site
can reproduce this issue either.
I got this due to forgetting that I installed Django using pip -U
, so it was only available to the user running my Django app. To run manage.py I had to do
sudo su -s /bin/bash MY_DJANGO_USER
/PATH/TO/MY/APP/manage.py
all of you guys didn't mention a case where someone "like me" would install django befor installing virtualenv...so for all the people of my kind ther if you did that...reinstall django after activating the virtualenv..i hope this helps
참고URL : https://stackoverflow.com/questions/6049933/django-import-error-no-module-named-core-management
'Programming' 카테고리의 다른 글
X 시간보다 오래된 파일을 삭제하는 방법 (0) | 2020.05.18 |
---|---|
androidJUnit4.class는 더 이상 사용되지 않습니다 : androidx.test.ext.junit.runners.AndroidJUnit4를 사용하는 방법은 무엇입니까? (0) | 2020.05.18 |
정수를 삽입하려고 할 때 MongoDB 삽입 부동 (0) | 2020.05.18 |
data.table에서 이름으로 열을 어떻게 삭제합니까? (0) | 2020.05.18 |
보안 웹 서비스 : HTTPS를 통한 REST 대 SOAP + WS- 보안. (0) | 2020.05.18 |