[英]/usr/bin/python3: No module named pytest
I use python3 -m pytest
to run my tests.我使用
python3 -m pytest
来运行我的测试。 This was working when python3 was pointing to python3.6.当 python3 指向 python3.6 时,这是有效的。 I installed python3.7, made python3.7 as my default python3 with these commands:
我安装了 python3.7,使用以下命令将 python3.7 作为我的默认 python3:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
sudo update-alternatives --config python3
and installed all the required packages again for python3.7.并为python3.7再次安装了所有必需的包。 But now I cannot run my tests anymore.
但是现在我不能再运行我的测试了。 Because it says:
/usr/bin/python3: No module named pytest
.因为它说:
/usr/bin/python3: No module named pytest
。 I'm not using virtual env and the problem is not about a specific module, because it cannot find other modules either.我没有使用虚拟环境,问题不在于特定模块,因为它也找不到其他模块。 It should be related to python paths.
它应该与python路径有关。 I don't know what to change after switching between python3 versions so it can easily find the required modules in
/home/ubuntu/.local/lib/python3.x/site-packages/
.我不知道在 python3 版本之间切换后要更改什么,因此它可以轻松地在
/home/ubuntu/.local/lib/python3.x/site-packages/
找到所需的模块。
I switched back to python3.6 and getting ModuleNotFoundError: No module named 'jsonpath_ng'
now, which was working before switching to python3.7.我切换回 python3.6 并得到
ModuleNotFoundError: No module named 'jsonpath_ng'
now,它在切换到 python3.7 之前工作。 This is the output of python3 -m site
:这是
python3 -m site
的输出:
sys.path = [
'/home/ubuntu',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/ubuntu/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/ubuntu/.local' (exists)
USER_SITE: '/home/ubuntu/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True
Thank you to @hoefling, I found the problem by running python3 -m site
.感谢@hoefling,我通过运行
python3 -m site
发现了问题。 I was running tests with my jenkins user and not the root, while I was installing everything for the root user.我正在使用我的 jenkins 用户而不是 root 运行测试,而我正在为 root 用户安装所有东西。 So USER_SITE didn't actually exist for jenkins user.
所以 USER_SITE 对于 jenkins 用户来说实际上并不存在。 I installed everything again for the jenkins user and now it can find the modules when I use
python3 -m
.我为 jenkins 用户再次安装了所有东西,现在当我使用
python3 -m
时它可以找到模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.