Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在虚拟环境中找到Django安装?_Python_Django_Pip_Virtualenv - Fatal编程技术网

Python 如何在虚拟环境中找到Django安装?

Python 如何在虚拟环境中找到Django安装?,python,django,pip,virtualenv,Python,Django,Pip,Virtualenv,我已经在虚拟环境中安装了Django,但是当我调用包时,它没有显示 $ pip install django Downloading/unpacking django Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded Installing collected packages: django Successfully installed django Cleaning up... $ python

我已经在虚拟环境中安装了Django,但是当我调用包时,它没有显示

$ pip install django
Downloading/unpacking django
  Downloading Django-1.7.1-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
$ python 
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django
$pip安装django
下载/解包django
下载Django-1.7.1-py2.py3-none-any.whl(7.4MB):下载7.4MB
安装收集的软件包:django
已成功安装django
清理。。。
$python
Python 2.7.6(默认,2014年9月9日,15:04:36)
[GCC 4.2.1达尔文兼容苹果LLVM 6.0(clang-600.0.39)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>进口django
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为django的模块

如何在我的虚拟环境中找到我的Django安装?

virtualenv
使用系统python安装路径前的路径扩展/覆盖您的系统python环境。您可以看到,您
。virtualenv
站点包列在系统
站点包之前,这就是它的工作原理

需要记住的是,activate会修补当前的命令行环境,因此在运行python代码之前,必须先运行
activate
,具体取决于
virtualenv

更新:

解决办法是

simon@ri-desktop:~$ mkdir test
simon@ri-desktop:~$ cd test/
simon@ri-desktop:~/test$ ls
simon@ri-desktop:~/test$ virtualenv env
New python executable in env/bin/python
Installing setuptools, pip...done.
simon@ri-desktop:~/test$ ls
env
simon@ri-desktop:~/test$ source env/bin/activate
(env)simon@ri-desktop:~/test$ ls
env
(env)simon@ri-desktop:~/test$ mkdir project
(env)simon@ri-desktop:~/test$ ls
env  project
(env)simon@ri-desktop:~/test$ cd project/
(env)simon@ri-desktop:~/test/project$

您是否激活了虚拟环境source bin/activate
和windows上的
\path\to\env\Scripts\activate
…此处的
enter code
是错误消息的一部分还是粘贴在此处的代码中留下的?是的,我取出了名称,但已将其激活。当您执行
pip list
时,是否看到django?(venv)-MacBook Pro:my_project_文件夹j$pip list Django(1.7.1)pip(1.5.6)setuptools(3.6)wsgiref(0.1.2)如果我理解正确,请运行activate?以下是回复:(my_project_文件夹)MacBook Pro:my_project_文件夹j$activate-bash:/Users/j/Desktop/my_project_文件夹/bin/activate:Permission deniedI我完成了您的步骤,但这次我遇到了导入错误<代码>(env)MacBook Pro:test j$ls env project(env)MacBook Pro:test j$cd project(env)MacBook Pro:project j$pip install django Downloading/unpacking django Downloading/unpacking django Downloading django-1.7.1-py2.py3-none-any.whl(7.4MB):下载7.4MB安装收集的软件包:django成功安装django清理。。。(env)MacBook Pro:project j$import django-bash:import:command未找到这不是检查django的正确方法。首先输入
python
,然后输入
import django
。。只是那样。。明白了吗?这似乎可以让shell内部工作,但当我这样做时:
python import django
我仍然得到
(env)-MacBook Pro:project j$python import django/usr/bin/python:无法打开文件“import”:[Errno 2]没有这样的文件或目录