本文介绍了在virtualenv中创建项目时,没有名为django.core的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我看了很多类似于我的问题,但是我找不到具体的答案。我的comp规格是Windows 7 64位。

So I have looked around at a lot of questions similar to mine, however I couldn't find a concrete answer. My comp specifications are Windows 7 64-bit.

我的问题是这样的:

1)我使用pip安装了virtualenv:

1) I installed virtualenv using pip:

pip install virtualenv

2)之后,我创建并激活了一个新环境:

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

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

3)在运行新的环境时,我安装了django :

3) While running the new environment, I installed django:

(env) path/pip install django

4)安装成功后,我准备做一个项目。但是,尝试一下:

4) After installing successfully, I am ready to make a project. However, upon trying it out:

path/django-admin.py startproject test

我收到以下错误:

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 out various solutions people have posted, including using the full path:

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

我还检查过,确保引用的Python版本是正确的,因为在virtualenv内部和外部都与Python27相关联。许多其他解决方案都谈到了PYTHONPATH或syspath,但是当我在python shell中导入django或者managemnet时,那些工作正常。

I have also checked to make sure the versions of Python it is referencing are correct,as both inside and outside the virtualenv it is associated with Python27. Many other solutions talked about PYTHONPATH or the syspath, however, when I import django or managemnet in the python shell, those work fine.

我有一种感觉,它可能有东西与路径有关,但我不知道virtualenv如何与系统路径进行交互。由于它是独立的,系统路径是系统的,是否有必要在路径中有特定的东西?

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

除此之外,我的django-admin.py文件位于

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

path/env/Scripts

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

,django文件夹位于

and the django folder is in

path/env/Lib/site-packages

如何修复这个问题?

推荐答案

我使用这个命令解决了这个问题:

I solved this problem by using this command as following instead:

django-admin startproject

只需删除附加到django-admin的.py

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

这篇关于在virtualenv中创建项目时,没有名为django.core的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 17:59