我正在使用用Python实现的工具nrfutil
。为了能够在NixOS下使用它,我使用了一个default.nix
文件,该文件将nrfutil安装到一个venv中。这在一段时间内效果很好。(在alpine容器中使用Nix在构建服务器上的最后一次构建可以成功构建我11天前正在使用的软件。)当我执行完全相同的操作(即在不进行更改的情况下重新启动CI服务器构建)时,构建现在失败,抱怨pip
不正确:
$ nix-shell
New python executable in /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
Not overwriting existing python script /home/matthias/source/tbconnect/bootloader/.venv/bin/python (you must use /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7)
Installing pip, wheel...
done.
Traceback (most recent call last):
File "/home/matthias/source/tbconnect/bootloader/.venv/bin/pip", line 6, in <module>
from pip._internal.main import main
ImportError: No module named main
在我看来,模块main
应该存在:
$ ls -l .venv/lib/python2.7/site-packages/pip/_internal/main.py
-rw-r--r-- 1 matthias matthias 1359 10月 15 12:27 .venv/lib/python2.7/site-packages/pip/_internal/main.py
我不太熟悉Python环境,所以我不知道更多。有人告诉我在哪里继续调试吗?Python如何解析模块?为什么它找不到模块,它似乎呈现在我面前
这是我用来安装pip
的default.nix
:
with import <nixpkgs> {};
with pkgs.python27Packages;
stdenv.mkDerivation {
name = "impurePythonEnv";
buildInputs = [
automake
autoconf
gcc-arm-embedded-7
# these packages are required for virtualenv and pip to work:
#
python27Full
python27Packages.virtualenv
python27Packages.pip
# the following packages are related to the dependencies of your python
# project.
# In this particular example the python modules listed in the
# requirements.txt require the following packages to be installed locally
# in order to compile any binary extensions they may require.
#
taglib
openssl
git
stdenv
zlib ];
src = null;
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv --no-setuptools .venv
export PATH=$PWD/.venv/bin:$PATH
#pip install nrfutil
pip help
# the following is required to build micro_ecc_lib_nrf52.a in the SDK
export GNU_INSTALL_ROOT="${gcc-arm-embedded-7}/bin/"
unset CC
'';
}
pip help
替换了pip install nrfutil
,以确保问题不是我试图安装的包本身李>nrfutil
仍然不适合Python3李>python37
替换python27
并没有改变我在尝试启动pip
时遇到的错误。)nixos/nix:latest
,它是Alpine Linux上的Nix包管理器李>更新:
实际上,当我将对pip install nrfutil
的调用替换为python2.7 -m pip install nrfutil
时,它就工作了。这实际上让我更加困惑。python2.7正是pip的shebang中的二进制代码:
[nix-shell:~/source/tbconnect/bootloader]$ type python2.7
python2.7 is /home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
[nix-shell:~/source/tbconnect/bootloader]$ type pip
pip is /home/matthias/source/tbconnect/bootloader/.venv/bin/pip
[nix-shell:~/source/tbconnect/bootloader]$ head --lines 2 .venv/bin/pip
#!/home/matthias/source/tbconnect/bootloader/.venv/bin/python2.7
# -*- coding: utf-8 -*-
更新2:
我发现另一种解决问题的方法是编辑.venv/bin/pip
。此脚本尝试了以下导入:
from pip._internal.main import main
我认为这是从PIP19.3开始的新模块路径。但我还有PIP19.2。当我将此行更改为:
from pip._internal import main
通过键入pip
运行pip
正在工作
问题是我不知道为什么pip
脚本试图加载新的模块路径,而NixOS仍然拥有旧版本的pip
我还为NixOS在GitHub上发行了一期:https://github.com/NixOS/nixpkgs/issues/71178
我通过删除
Python27Packages.pip
使您的shell派生正常工作还有我的默认.nix
相关问题 更多 >
编程相关推荐