Python Pip3 安装模块在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33906336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is Pip3 Installing Modules?
提问by Zamphatta
- Ubuntu 15.10
- Python 3.4.3+
- Django 1.8.7
- Ubuntu 15.10
- 蟒蛇 3.4.3+
- Django 1.8.7
When I try to import django
in the python3 interpreter, it says ImportError: No module named 'django'
. I know Django 1.8.7 installed though, 'cause I can get the version # by doing django-admin --version
in the terminal commandline.
当我尝试import django
在 python3 解释器中时,它说ImportError: No module named 'django'
. 我知道安装了 Django 1.8.7,因为我可以通过django-admin --version
在终端命令行中执行来获取版本 # 。
When I tried python3 manage.py runserver
in a Django project directory, I get this error:
当我python3 manage.py runserver
在 Django 项目目录中尝试时,出现此错误:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
So again (as expected), it's not in a path where Python can find it.
所以再次(正如预期的那样),它不在 Python 可以找到它的路径中。
I looked in /usr/local/lib/python3.4/dist-packages
but it's an empty directory.
我看了看,/usr/local/lib/python3.4/dist-packages
但它是一个空目录。
I did a whereis django
& whereis Django
and that simply gives me a line with django:
or Django:
respectively and no list of paths.
我做了一个whereis django
& whereis Django
,它只是给了我一行 django:
或Django:
分别没有路径列表。
I tried Googling how to find path to Django, but that didn't turn up anything useful.
我尝试谷歌搜索如何找到 Django 的路径,但这并没有发现任何有用的东西。
I found & checked the code of the django-admin file itself, but it doesn't have anything indicating where Django installed to. Oddly, the python file imports the django module and it works, even though the interpreter & Django project files can't see the django module. So it's on the python path but it also isn't?!? I don't know, and I can't find it.
我发现并检查了 django-admin 文件本身的代码,但它没有任何指示 Django 安装到的位置。奇怪的是,python 文件导入了 django 模块并且它可以工作,即使解释器和 Django 项目文件看不到 django 模块。所以它在python路径上,但它也不是?!?我不知道,我也找不到。
I never had a problem like this with a previous Ubuntu (or any other OS). Has anyone got a clue how I can find where Django installed? Actually, I can't find any of the modules I installed via pip3. I've been trying to figure this out for over an hour now, and I'm very confused & frustrated.
我在以前的 Ubuntu(或任何其他操作系统)上从来没有遇到过这样的问题。有没有人知道我如何找到 Django 的安装位置?实际上,我找不到任何通过 pip3 安装的模块。一个多小时以来,我一直在努力解决这个问题,我感到非常困惑和沮丧。
采纳答案by Zartch
Normally pip 3 install on python3 dist-packages
通常在 python3 dist-packages 上安装 pip 3
You can always use pip with:
您始终可以将 pip 用于:
python3 -m pip install package
to check if you are experiencing troubles with another python3 installation
检查您是否在安装另一个 python3 时遇到问题
ls /usr/local/lib | grep python
But the easy way to not experiment this headache is by using virtual environments
但是不尝试这种头痛的简单方法是使用虚拟环境
回答by Sapanjeet
I think you have installed django outside virtual environment. download virtual environment by
我认为您已经在虚拟环境之外安装了 django。下载虚拟环境
pip install virtualenv
virtualenv your_env
Activate virtual environment.
激活虚拟环境。
source your_env/bin/activate
Then, Install django in your virtual environment.
然后,在您的虚拟环境中安装 django。