There is no module named django.core when creating a project in virtualenv

Therefore, I looked through a lot of questions similar to mine, however I did not find a specific answer. My specs Comp is the 64-bit version of Windows 7.

My problem is this:

1) I installed virtualenv using pip:

pip install virtualenv 

2) After that, I created and activated a new environment:

 path/virtualenv env ... path/to/env/Scripts/activate 

3) When starting a new environment, I installed django:

 (env) path/pip install django 

4) After a successful installation, I am ready to make a project. However, by trying:

 path/django-admin.py startproject test 

I get the following error:

 File "C:/path/env/Scripts/django-admin.py", line 2, in (module) from django.core import management ImportError: No module named django.core 

I have tried various solutions posted by users, including the full path:

 python C:/path/to/django-admin.py startproject test 

I also verified that the versions of Python they are referencing are correct, since both inside and outside of virtualenv it is linked to Python27. Many other solutions talked about PYTHONPATH or syspath, however when I import django or manageemnet into the python shell, they work fine.

I have a feeling that it may have something to do with paths, but I'm not sure how the virtual interface interacts with system paths. Since it is self-sufficient and the system paths are systemic, is it necessary to have something in the path specifically?

As an aside, my django-admin.py file is in both

 path/env/Scripts 

and

 path/env/Lib/site-packages/django/bin 

and the django folder is in

 path/env/Lib/site-packages 

How to solve this problem?

+8
django path virtualenv
source share
11 answers

I solved this problem using the following command:

django-admin startproject

just remove the ".py" attached to "django-admin"

+6
source share

I could not get any other stack overflow answers for work. Getting the embedded Django stack running on Win64 is a bit of a challenge.

But I found an answer that worked for me here: http://samudranb.com/2012/06/02/how-to-setup-a-djangopython-development-env-on-windows/

Try running the admin command prompt:

 ftype Python.File="[your venv path]\Scripts\python.exe" "%1" %* 

Be sure to return to its original value when done.

+4
source share

This will help you understand why you came across this problem, and there is also a simple solution for this:

http://blog.jayteebee.org/2009/07/importerror-no-module-named-djangocore.html

+2
source share

Windows 2003 server provides the Where command where python.exe

will show the full path of the current python.exe found on the path, use this to check it using the correct one for your virtualenv.

An association problem comes into play because file.py is executed so .py argv [0] passes it through the windows association, which will not follow your wreath.

python file.py will not find file.py if it is not in the current directory.

So the solution is

python% VIRTUAL_ENV% \ scripts \ django-admin.py startproject myproject

This starts python from the currently active venv and uses the venv env variable to point to the correct location of django-admin.py (or you could give it an absolute path yourself)

+1
source share

I literally looked for several hours to solve this problem ... I accidentally met this video: ( https://www.youtube.com/watch?v=lPmkl4jtYgA ) where he put "python. \ Script \ django-admin.py startproject "to the command line in a virtual environment, so I tried the same with the following modification to point to the correct path on my python machine. env \ Script \ django-admin.py startproject ". Voila!

Hope this helps someone, as there are apparently several reasons for this problem.

+1
source share

I had the same problem using virtualenv in Terminal on MacOSX (Snow Leopard). My solution to the problem was to change the first line of django-admin.py from

 #!/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python 

to

 #!/path-to-your-virtualenv-directory/bin/python 

Hope this helps someone.

0
source share

I had the same problem. I decided that with this command: (env) C: \ environment directory> python scripts \ django-admin.py

This link was useful to me: enter the link here

0
source share

I had the same problem, I run both python 3.4 and 2.7, so I installed Django globally on my computer, and when I returned to my virtual environment, I was able to create a project without problems.

0
source share

I had the same problem and resolved it by activating the project directory before doing the migration and starting my server "python manage.py runningerver" . Activate the project directory: source / path / bin / active The path means where your project is stored.

0
source share

There was the same mistake, and this solved it for me.

source / path / to / virtualwrapper / activate

pip install django

This hotfix is ​​trying to reinstall and configure django
0
source share

I had the same problem, but I solved, first activated virtual env, and then ran:

django-admin.exe startproject project_name

0
source share

All Articles