【问题标题】:python django pip update problems: how to get compatible versions?python django pip 更新问题:如何获得兼容版本?
【发布时间】:2018-04-28 04:55:23
【问题描述】:

我尝试在托管服务器 (Ubuntu 16.04) 上运行 django 演示项目:它运行良好。 然后我尝试在本地机器上运行相同的代码:

Unhandled exception in thread started by <function wrapper at 0x7fc0c4403f50>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 127, in create
    import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named about

因此,我尝试更新 django 安装(它的版本可能比服务器旧)。

所以我尝试了 pip django 更新:

sudo pip install -U django

导致了这个错误:

The directory '/home/lxuser/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/lxuser/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: django in /usr/local/lib/python2.7/dist-packages (1.11.12)
Requirement not upgraded as not directly required: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2018.4)
requests 2.18.4 has requirement certifi>=2017.4.17, but you'll have certifi 0.0.8 which is incompatible.

所以我尝试了这个:

sudo -H pip install -U django

现在错误是:

Requirement already up-to-date: django in /usr/local/lib/python2.7/dist-packages (1.11.12)
Requirement not upgraded as not directly required: pytz in /usr/local/lib/python2.7/dist-packages (from django) (2018.4)
requests 2.18.4 has requirement certifi>=2017.4.17, but you'll have certifi 0.0.8 which is incompatible.

所以有错误但Django安装似乎不是太旧。

所以我想问更一般的:

我如何确保 django 版本(以及依赖库) 相同或至少如此相似,以至于我可以运行相同 没有代码不兼容的项目代码?

如何以同步方式更新两个系统(例如托管服务器和本地开发系统)上的版本?

【问题讨论】:

    标签: python django pip


    【解决方案1】:

    使用a requirements file

    1. 在工作系统上,做pip freeze &gt; requirements.txt

    2. 复制该文件(我总是签入一个作为我的存储库的一部分)

    3. 在新机器上,可能是在虚拟环境中,你可以用pip install -r requirements.txt更新到那些版本

    【讨论】:

    • 很好。谢谢!
    • 尝试使用 pip 安装需求:Could not find a version that satisfies the requirement python-apt==1.1.0b1 (from -r requirements.txt (line 3)) (from versions: 0.0.0, 0.7.8) No matching distribution found for python-apt==1.1.0b1 (from -r requirements.txt
    • 对不起,我不熟悉那个包。看起来它是一个测试版,可能还没有进入 pip,但这非常令人惊讶。通常您可以使用pip install --pre 获得预发布版本。如果你真的需要这个版本的这个包,可能值得发布一个新问题。
    • 谢谢。我不确定这里发生了什么:我所做的只是用 Ubuntu 16.04 启动一个系统。然后是三个标准命令:sudo apt-get install python-pipsudo pip install --upgrade pipsudo pip install Django==1.11 这些版本似乎很典型,所以我不太明白为什么要求最终如此特殊。我将进一步研究virualenv,也许这会有所帮助。
    【解决方案2】:

    正如 RishiG 所说,您应该创建一个包含项目依赖项的 requirements.txt 文件,但大多数情况下您应该使用virtual environnement。它将允许您为每个项目隔离您的 python 版本和包及其版本。

    【讨论】:

      猜你喜欢
      • 2013-04-20
      • 2023-03-31
      • 2013-10-11
      • 2021-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 1970-01-01
      相关资源
      最近更新 更多