简体   繁体   English

找不到`pip install -r requirements.txt`安装的软件包

[英]Packages installed by `pip install -r requirements.txt` are not found

I'm trying to run an inherited Django project. 我正在尝试运行一个继承的Django项目。 I've set up a virtualenv and tried to pass in the requirements file via pip install -r requirements.txt . 我已经设置了virtualenv并尝试通过pip install -r requirements.txt传递需求文件。 Everything seems to work. 一切似乎都正常。 It tells me it's working in the correct virtualenv, and packages appear to install, eg: 它告诉我它正在正确的virtualenv中运行,并且软件包似乎已安装,例如:

Downloading/unpacking django-mediasync==2.2.0 (from -r requirements.txt (line 22))
  Downloading django-mediasync-2.2.0.tar.gz
  Running setup.py egg_info for package django-mediasync

But when I try to syncdb or runserver, 但是当我尝试同步数据库或运行服务器时,

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x10f15e290>>
Traceback (most recent call last):
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 88, in inner_run
    self.validate(display_num_errors=True)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/core/management/validation.py", line 36, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/db/models/loading.py", line 76, in load_app
    app_module = import_module(app_name)
  File "/Users/me/.virtualenvs/example/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named mediasync

What's weird is that I install mediasync (or any other necessary packages) manually ( pip install django-mediasync ), the package can now be found. 奇怪的是,我手动安装了mediasync (或任何其他必要的软件包)( pip install django-mediasync ),现在可以找到该软件包。

What am I doing wrong? 我究竟做错了什么? I don't want to have to install all of these packages manually. 我不想手动安装所有这些软件包。

I think when doing: pip install -r requirements.txt there was some error but you didn't notice. 我认为这样做时: pip install -r requirements.txt出现了一些错误,但您没有注意到。 Basically the whole operation will stop at the time there is error. 基本上,整个操作将在出现错误时停止。

So for example your requirements.txt have 4 packages like this: 因此,例如,您的requirements.txt具有4个这样的包:

A
B
C
D

If there is an error when installing B , 3 packages B , C and D will not be installed. 如果在安装B时出错,则不会安装3个软件包BCD It seems to me that there was an error with installation of one package in your requirements.txt and it didn't install django-mediasync at all. 在我看来,在您的requirements.txt安装一个软件包时出现错误,并且根本没有安装django-mediasync

If my hypothesis is right, please do pip install -r requirements.txt and check the last part of the traceback. 如果我的假设正确,请执行pip install -r requirements.txt并检查回溯的最后一部分。 If something fails, you will know exactly why. 如果出现故障,您将确切知道原因。

Are you doing sudo pip install django-mediasync or sudo pip install -r requirements.txt ? 您正在执行sudo pip install django-mediasyncsudo pip install -r requirements.txt吗? If so, it'll install it outside of the virtualenv. 如果是这样,它将安装在virtualenv之外。 See How to install which programs requires "sudo" in virtualenv? 请参阅如何在virtualenv中安装哪些程序需要“ sudo”? .

Basically because your user should own the virtualenv directory, you don't need superuser privileges to install anything via pip. 基本上因为您的用户应该拥有virtualenv目录,所以您不需要超级用户特权即可通过pip安装任何内容。 Do which pip and sudo which pip and you will see they are different. 进行which pipsudo which pip ,您将看到它们是不同的。

The other possibility may be that your requirements.txt is not installing correctly. 另一种可能是您的requirements.txt安装不正确。 It may output lines like the line you mention, but apparently pip will scan all the packages in the requirements.txt before installing anything. 它可能会输出与您提到的行类似的行,但是显然pip会在安装任何组件之前扫描requirements.txt中的所有软件包。 If there is any error, it will abort the install for all packages. 如果有任何错误,它将中止所有软件包的安装。

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

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