python需求:如何获得相同的版本?

python需求:如何获得相同的版本?,python,virtualenv,pipenv,Python,Virtualenv,Pipenv,这个问题是校长提出的 需求规范的解决方案: 我尝试在服务器之间同步python需求 以及本地发展系统。两者都是Ubuntu 16.04。, 所以这应该是个问题。 服务器给了我一个需求文件(在pip安装django之后,如另一个问题中所述) 但是pip在本地机器上安装需求会产生一些错误, 像这样: Could not find a version that satisfies the requirement python- apt==1.1.0b1 (from -r requiremen

这个问题是校长提出的 需求规范的解决方案:

我尝试在服务器之间同步python需求 以及本地发展系统。两者都是Ubuntu 16.04。, 所以这应该是个问题。 服务器给了我一个需求文件(在pip安装django之后,如另一个问题中所述)

但是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

setup(
    # ...
    dependency_links = [
        "http://packages.example.com/snapshots/",
        "http://example2.com/p/bar-1.0.tar.gz",
    ], ) ```

This “feature” of setuptools removes the abstractness of its
dependencies and hardcodes an exact url from which you can fetch the
dependency from. Now very similarly to Go if we want to modify
packages, or simply fetch them from a different server we’ll need to
go in and edit each package in the dependency chain in order to update
the dependency_links.
是否有一种方法可以确保在类似系统上满足要求 而不会出现由于版本不兼容而导致的错误 (或因故交替解决不兼容问题)

我需要虚拟环境来解决这个问题吗? 甚至是pipenv? 或者有没有一种简单直接的方法可以让两个系统同时运行
兼容python和包环境吗?

事实上,
python apt
的最新版本是0.7.8

如果您100%确定它是同一个包,请尝试在requirements.txt文件中更改它

另一方面,您可以尝试查看本地服务器上的
python apt
在哪里

import apt
print(apt.__file__)  # or print(apt.__path__)
然后,去那里手动检查一下那
python apt
包到底是什么。

问题 此特定模块(
python apt
)是。然而,这次发布似乎是一个错误

python apt的开发者之一&Debian包维护者:

啊,又不是这整件事了。从来没有人正式 上传了
python apt
。它与APT紧密耦合,并且 不得以除via以外的任何方式分发 Debian软件包

没有,也从来没有任何人支持PyPi。我可以 说我对在那里复制工作完全没有兴趣。

您可以从apt安装
python apt
,我们不在
pip
上提供
python apt
。我最近控制了pypi条目,需要对它做些什么。我不喜欢在发行版之外提供
python-apt
,但是(
python-apt
和apt版本x.y需要匹配),所以我宁愿放弃它,这样人们就不会再问过时的版本了。

因此,至少对于这种依赖关系,当我们通过
pip
+PyPi以python本机方式解析依赖关系时,似乎运气不好。幸运的是,上游项目托管在
salsa.debian.org
GitLab实例上,
pip
现在支持
git+
SCM URL以及其他选项

解决: 通常,有许多解决方案可以解决这种依赖关系。您试图解决的问题包括:

  • 这个包裹是从哪里提供的?
    • 系统操作系统包管理器
    • 任意上游发布URL
    • 发展供应链回购
    • 带有错误修复的叉式Git回购
    • 等等
  • 您将安装哪个版本?
    • 兼容性问题:
      • 必须是
        >=2.0.0
      • 分叉回购/功能分支,带有一些错误修复
      • API兼容性:不大于
        2.x
        /
    • 发展:
      • 只需使用最新和最好的(最前沿)
      • 为我的平台或系统使用特定版本(例如:系统操作系统包、开发目录中的本地分叉版本)
    • 质量保证/测试:
      • 针对特定版本进行测试
      • 针对最新版本进行测试(例如:夜间版本)
      • 根据系统操作系统版本提供的版本进行测试
  • 如何解决依赖关系?
    • “抽象”依赖于
      pip模块名称
      +
      版本约束
      • 允许以后使用where收集(URL/PyPi/Artifactory)和允许什么版本满足约束的灵活性
      • 如果需要,用户可以通过为
        pip
        指定参数、使用特定的
        virtualenv
        进行安装等来覆盖这些参数
    • 对特定URL+包名+版本的“具体”依赖关系
      • 极端情况:锁定到特定URL+版本+
        sha1/sha256/sha**
        ,并进行校验和验证,以确保准确的位置和文件完整性
      • 灵活性较低,但最可靠的是锁定到精确的版本和来源
  • 您是在开发“应用程序”还是“库”/Python模块?
    • 依赖项是否需要通过
      pip
      使用
      setup.py
      install\u requires=[…]
      样式解析来安装?(图书馆)
    • 应用程序安装程序是否需要通过
      pip install-r requirements.txt
      安装依赖项?(申请)
  • 您的项目将如何发布?
    • 谁将安装软件包,以及如何允许他们的系统解决依赖关系
    • 这将在PyPi上作为库发布,还是作为应用程序发布?(以下是一些经验法则)
      • 一般来说:
        • 一个库倾向于拥有广泛的开放式版本说明符
        • 应用程序需要非常特定的依赖项来确保稳定性(大量依赖项意味着大量未经测试的版本排列!)
      • 使用
        setup.py
        指定PyPi的库依赖项
      • 使用
        requirements.txt
        指定应用程序的依赖项
    • 这将被打包为本机操作系统包吗?(例如:
      .deb
      .rpm
      .apk
      等)
      • 本机包管理器也有依赖项解析。。。也许可以使用它来确保本机兼容性
    • 您的软件包将支持哪些其他操作系统平台&这些平台将如何解决依赖关系
所以,大多数
--index-url https://pypi.python.org/simple/

-e git+https://salsa.debian.org/apt-team/python-apt.git#egg=python-apt
-e .
[...SNIP...] # Boilerplate stuff here

setup(

#[...SNIP...] # Other setup() args here

    platforms=['linux'],
    # Reference:
    #  - https://github.com/pypa/interoperability-peps/pull/30/files#r184839487
    # sudo apt install python3-apt apt-rdepends apt
    # os_requires=[
    #     ['python3-apt', type='packagename', target='run', os='ubuntu'],
    #     ['apt-rdepends', type='packagename', target='run', os='ubuntu'],
    #     ['apt', type='packagename', target='run', os='ubuntu']
    #     ['libapt-pkg-dev', type='packagename', target='build', os='ubuntu']
    # ]
    # Build-deps for apt-python via git SCM: sudo apt install libapt-pkg-dev 
    python_requires='>=3.5',
    install_requires=[
        'python-apt (>= 2.0)',
        # rest of your dependencies here
        #[... SNIP ...]
    ],
    package_dir={'': 'lib'},
    scripts=_glob('bin/*'),

#[...SNIP...]

)
$ pip3 install -r requirements.txt
Looking in indexes: https://pypi.python.org/simple/
Obtaining file:///../example-project (from -r requirements.txt (line 4))
Obtaining python-apt from git+https://salsa.debian.org/apt-team/python-apt.git#egg=python-apt (from -r requirements.txt (line 3))
  Updating ./example-project-venv/src/python-apt clone
  Running command git fetch -q --tags
  Running command git reset --hard -q c97d4159beae2f9cd42d55d3dff9c37f5c69aa44
ERROR: example-project 0.0.1 has requirement python-apt>=2.0, but you'll have python-apt 0.0.0 which is incompatible.
Installing collected packages: python-apt, example-project
  Running setup.py develop for python-apt
  Running setup.py develop for example-project
Successfully installed example-project python-apt
# Runtime deps (e.g.: Ubuntu 20.04 needs python3-apt, <20.04 needs python-apt):
sudo apt install python3-apt apt
# python-apt pip install deps (also for setup.py / development)
sudo apt install libapt-pkg-dev

setup(
    # ...
    dependency_links = [
        "http://packages.example.com/snapshots/",
        "http://example2.com/p/bar-1.0.tar.gz",
    ], ) ```

This “feature” of setuptools removes the abstractness of its
dependencies and hardcodes an exact url from which you can fetch the
dependency from. Now very similarly to Go if we want to modify
packages, or simply fetch them from a different server we’ll need to
go in and edit each package in the dependency chain in order to update
the dependency_links.

setup(
    # [...SNIP...]
    dependency_links = [
        "https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz#egg=python-apt"
    ],
    # [...SNIP...]
) `
setup(
    # [...SNIP...]
    install_requires=[
        'python-apt@https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz#sha256=1ddbd3eb7cbc1ded7e0e8a2dd75219f0c59c7e062c6e6bfd5c8ff6f656c59a4e',
        # [...SNIP...]
    ],
    # [...SNIP...]
)
--index-url https://pypi.python.org/simple/

-e .

$ ./example-project-venv/bin/python3 ./example-project-venv/bin/pip3 install -r requirements.txt 
Looking in indexes: https://pypi.python.org/simple/
Obtaining file://./src/pub/example-project (from -r requirements.txt (line 4))
Requirement already satisfied: graph-tools>=1.5 in ./example-project-venv/lib/python3.8/site-packages (from example-project==0.0.1->-r requirements.txt (line 4)) (1.5)
Collecting python-apt@ https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz#sha256=1ddbd3eb7cbc1ded7e0e8a2dd75219f0c59c7e062c6e6bfd5c8ff6f656c59a4e
  Using cached https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz (458 kB)
Building wheels for collected packages: python-apt
  Building wheel for python-apt (setup.py) ... done
  Created wheel for python-apt: filename=python_apt-0.0.0-cp38-cp38-linux_x86_64.whl size=2040980 sha256=79eeb0d1bb9e3c9785acb68f164a3f72a5777539137d180e9ded7558d2547a49
  Stored in directory: ~/.cache/pip/wheels/c4/09/b5/36fc8c9a1ebe8786620db922f1495da200dce187ee7c618993
Successfully built python-apt
Installing collected packages: python-apt, example-project
  Attempting uninstall: example-project
    Found existing installation: example-project 0.0.1
    Uninstalling example-project-0.0.1:
      Successfully uninstalled example-project-0.0.1
  Running setup.py develop for example-project
Successfully installed example-project python-apt-0.0.0
$ ./example-project-venv/bin/python3 ./example-project-venv/bin/pip3 install --find-links 'https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz' -r requirements.txt 
Looking in indexes: https://pypi.python.org/simple/
Looking in links: https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz
Obtaining file://./example-project (from -r requirements.txt (line 4))
Requirement already satisfied: graph-tools>=1.5 in ./example-project-venv/lib/python3.8/site-packages (from example-project==0.0.1->-r requirements.txt (line 4)) (1.5)
Collecting python-apt>=2.0
  Downloading https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz (458 kB)
     |████████████████████████████████| 458 kB 614 kB/s 
  WARNING: Requested python-apt>=2.0 from https://salsa.debian.org/apt-team/python-apt/-/archive/2.0.0/python-apt-2.0.0.tar.gz (from example-project==0.0.1->-r requirements.txt (line 4)), but installing version 0.0.0
Building wheels for collected packages: python-apt
  Building wheel for python-apt (setup.py) ... done
  Created wheel for python-apt: filename=python_apt-0.0.0-cp38-cp38-linux_x86_64.whl size=2040783 sha256=d0a8f88c04f202e948b9855837140517d9b2bd3cef72e626221614552a476780
  Stored in directory: ~/.cache/pip/wheels/8a/07/e9/b3c3328bac08c030a5b1e754e01e327b62fd26f9baedf07c15
Successfully built python-apt
ERROR: example-project 0.0.1 has requirement python-apt>=2.0, but you'll have python-apt 0.0.0 which is incompatible.
Installing collected packages: python-apt, example-project
  Attempting uninstall: python-apt
    Found existing installation: python-apt 0.0.0
    Uninstalling python-apt-0.0.0:
      Successfully uninstalled python-apt-0.0.0
  Attempting uninstall: example-project
    Found existing installation: example-project 0.0.1
    Uninstalling example-project-0.0.1:
      Successfully uninstalled example-project-0.0.1
  Running setup.py develop for example-project
Successfully installed example-project python-apt-0.0.0
/usr/lib/python2.7/dist-packages/numpy

/usr/lib/python3/dist-packages/numpy

ls -ls /usr/include/numpy
#-> ../lib/python2.7/dist-packages/numpy/core/include/numpy

ls -l /usr/include/python2.7/numpy
#->../../lib/python2.7/dist-packages/numpy/core/include/numpy

ls -l /usr/include/python3.5/numpy
#-> ../../lib/python3/dist-packages/numpy/core/include/numpy