简体   繁体   English

Pip3安装模块在哪里?

[英]Where is Pip3 Installing Modules?

  • Ubuntu 15.10 Ubuntu 15.10
  • Python 3.4.3+ Python 3.4.3+
  • Django 1.8.7 Django 1.8.7

When I try to import django in the python3 interpreter, it says ImportError: No module named 'django' . 当我尝试在python3解释器中import django时,它说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. 我知道安装了Django 1.8.7,因为我可以通过在终端命令行中执行django-admin --version来获得版本#。

When I tried python3 manage.py runserver in a Django project directory, I get this error: 当我在Django项目目录中尝试python3 manage.py runserver时,我收到此错误:

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 djangowhereis 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. 我发现并检查了django-admin文件本身的代码,但它没有任何指示Django安装到哪里的东西。 Oddly, the python file imports the django module and it works, even though the interpreter & Django project files can't see the django module. 奇怪的是,python文件导入了django模块并且它工作正常,即使解释器和Django项目文件无法看到django模块。 So it's on the python path but it also isn't?!? 所以它在python路径上,但它也不是?!? I don't know, and I can't find it. 我不知道,我找不到它。

I never had a problem like this with a previous Ubuntu (or any other OS). 我从来没有像以前的Ubuntu(或任何其他操作系统)这样的问题。 Has anyone got a clue how I can find where Django installed? 有谁知道我怎么能找到Django安装的地方? Actually, I can't find any of the modules I installed via pip3. 实际上,我找不到通过pip3安装的任何模块。 I've been trying to figure this out for over an hour now, and I'm very confused & frustrated. 我一直试图弄清楚这一点超过一个小时了,我很困惑和沮丧。

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 但是,不尝试这种头痛的简单方法是使用虚拟环境

I think you have installed django outside virtual environment. 我想你已经在虚拟环境之外安装了django。 download virtual environment by 下载虚拟环境

pip install virtualenv
virtualenv your_env

Activate virtual environment. 激活虚拟环境。

source your_env/bin/activate

Then, Install django in your virtual environment. 然后,在您的虚拟环境中安装django。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM