Mak*_*e42 6 python numpy anaconda conda python-poetry
到目前为止,我一直使用 conda 作为虚拟环境和依赖项管理。但是,将我的 environment.yml 文件从我的开发机器传输到生产服务器时,有些东西无法按预期工作。现在,我想研究替代方案。诗歌看起来不错,尤其是因为
诗歌还维护一个锁定文件,它比 pipenv 有好处,因为它跟踪哪些包是子依赖项。( https://realpython.com/effective-python-environment/#poetry )
这可能会大大提高稳定性。但是,我正在从事科学性很强的项目(矩阵、数据科学、机器学习),因此在实践中我需要 scipy 堆栈(例如 numpy、pandas、scitkit-learn)。
Python 对于一些纯计算工作负载来说变得太慢了,所以 numpy 和 scipy 诞生了。[...] 它们是用 C 编写的,只是包装成一个 python 库。
编译这样的库会带来一系列挑战,因为它们(或多或少)必须在您的机器上编译以获得最大性能并与 glibc 等库正确链接。
Conda 是作为一种多合一的解决方案引入的,用于为科学界管理 Python 环境。
[...] 不是在您的机器上使用脆弱的库编译过程,而是预编译库,并在您请求时才下载。不幸的是,该解决方案附带了一个警告 - conda 不使用 PyPI,这是最流行的 Python 包索引。
(https://modelpredict.com/python-dependency-management-tools#fnref:conda-compiling-challenges)
据我所知,这甚至不符合 Conda 的标准,因为它做了相当多的优化以充分利用我的 CPU/GPU/numpy 架构。( https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/#Myth-#6:-Now-that-pip-uses-wheels,-conda-is-no - 需要更长的时间)
https://numpy.org/install/本身建议使用 conda,但也说可以通过 pip 安装(而诗歌使用 pypi)
对于那些从个人喜好或阅读下面关于 conda 和 pip 之间的主要区别而知道他们更喜欢基于 pip/PyPI 的解决方案的用户,我们建议:
[...] 使用 Poetry 作为维护最良好的工具,它以与 conda 类似的方式提供依赖项解析器和环境管理功能。
我想获得诗歌设置的稳定性和 conda 设置的速度。
诗歌如何处理二进制依赖?它是否也像 conda 一样考虑我的硬件?
如果诗歌在这方面没有提供,我可以将它与 conda 结合起来吗?
numpywheel提供了针对不同操作系统、CPU 架构和 Python 版本的多个文件。wheel包是预编译的,因此目标系统不必编译包。
poetry能够根据您的系统为您选择合适的轮子。
话虽如此,我建议使用poetry,只要你只需要 python 包,这些包也可以在 pypi 上找到。一旦您需要其他非 python 工具,请坚持使用 conda。(免责声明:我是 的维护者之一poetry)。
另相关: https: //github.com/python-poetry/poetry/issues/1904
在 MAC Os BigSur (11.1) 上
\n我一整天都面临着 Python 3.9.1.6 和诗歌 1.1.4 的 numpy 安装失败(使用 pandas)的问题。
\n我知道诗歌使用 pip,当 pip <= 20.2.x 时,它不使用 numpy 的轮子版本。全新安装 Python 3.9.1.6 不会升级 pip!
\n这就是我设法安装我需要的东西的方法:
\n首先检查诗歌链接的Python默认版本(如果不合适就重新安装)
\npoetry env info | grep -i python\nPython: 3.9.1\nImplementation: CPython\nPython: /usr/local/Cellar/python@3.9/3.9.1_6/Frameworks/Python.framework/Versions/3.9\nRun Code Online (Sandbox Code Playgroud)\n安装您的项目并poetry init在没有任何您寻求的依赖项的情况下运行(您将poetry add <deps>在...之后使用 juste)
您应该获得类似于此 pyproject.toml 的内容:
\n[tool.poetry]\nname = "project1"\nversion = "0.1.0"\ndescription = ""\nauthors = [""]\n\n[tool.poetry.dependencies]\npython = "^3.9"\n\n[tool.poetry.dev-dependencies]\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n启动诗歌外壳
\n[tool.poetry]\nname = "project1"\nversion = "0.1.0"\ndescription = ""\nauthors = [""]\n\n[tool.poetry.dependencies]\npython = "^3.9"\n\n[tool.poetry.dev-dependencies]\n\n[build-system]\nrequires = ["poetry-core>=1.0.0"]\nbuild-backend = "poetry.core.masonry.api"\nRun Code Online (Sandbox Code Playgroud)\n此时升级 pip、wheel 和 setuptools!
\n\xe2\x9e\x9c project1 poetry shell\n\nPython 2.7 will no longer be supported in the next feature release of Poetry (1.2).\nYou should consider updating your Python version to a supported one.\n\nNote that you will still be able to manage Python 2.7 projects by using the env command.\nSee https://python-poetry.org/docs/managing-environments/ for more information.\n\nSpawning shell within /Users/vincent/Library/Caches/pypoetry/virtualenvs/project1-5XOg8Qie-py3.9\n\xe2\x9e\x9c project1 . /Users/vincent/Library/Caches/pypoetry/virtualenvs/project1-5XOg8Qie-py3.9/bin/activate\n(project1-5XOg8Qie-py3.9) \xe2\x9e\x9c project1\nRun Code Online (Sandbox Code Playgroud)\n现在安装应该没问题了
\n(project1-5XOg8Qie-py3.9) \xe2\x9e\x9c project1 $ pip install --upgrade pip wheel setuptools\nLooking in indexes: https://pypi.python.org/simple/\nCollecting pip\n Using cached pip-20.3.3-py2.py3-none-any.whl (1.5 MB)\nCollecting wheel\n Using cached wheel-0.36.2-py2.py3-none-any.whl (35 kB)\nCollecting setuptools\n Using cached setuptools-51.1.2-py3-none-any.whl (784 kB)\nInstalling collected packages: pip, wheel, setuptools\n Attempting uninstall: pip\n Found existing installation: pip 20.2.4\n Uninstalling pip-20.2.4:\n Successfully uninstalled pip-20.2.4\n Attempting uninstall: wheel\n Found existing installation: wheel 0.35.1\n Uninstalling wheel-0.35.1:\n Successfully uninstalled wheel-0.35.1\n Attempting uninstall: setuptools\n Found existing installation: setuptools 50.3.2\n Uninstalling setuptools-50.3.2:\n Successfully uninstalled setuptools-50.3.2\nSuccessfully installed pip-20.3.3 setuptools-51.1.2 wheel-0.36.2\nRun Code Online (Sandbox Code Playgroud)\n耶皮!
\n