简体   繁体   English

/usr/bin/python3: 没有名为 pytest 的模块

[英]/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.

相关问题 /usr/local/bin/python3:第 85 行或附近没有名为 pip 的模块错误; 以状态 1 退出 - /usr/local/bin/python3: No module named pip Error on or near line 85; exiting with status 1 /Applications/Xcode.app/Contents/Developer/usr/bin/python3:没有名为 notebook 的模块 - /Applications/Xcode.app/Contents/Developer/usr/bin/python3: No module named notebook /usr/local/bin/python: 没有名为 pip 的模块 - /usr/local/bin/python: No module named pip /usr/bin/python: 没有名为 pip 的模块 - /usr/bin/python: No module named pip /usr/bin/python3:查找“virtualenvwrapper.hook_loader”规范时出错(<class 'importerror'> : 没有名为“virtualenvwrapper”的模块)</class> - /usr/bin/python3: Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper') 为什么我得到 /usr/bin/python: No module named pip - Why do I get /usr/bin/python: No module named pip 与 /usr/bin/python3.4 /usr/bin/python3 的区别 - Difference with /usr/bin/python3.4 /usr/bin/python3 Ansible K8s 模块:无法在 Python /usr/bin/python3 上导入所需的 Python 库 (openshift) - Ansible K8s module: Failed to import the required Python library (openshift) on Python /usr/bin/python3 #!/usr/bin/python3 shebang 的目的 - Purpose of #!/usr/bin/python3 shebang 在 Jupyter 笔记本中使用 /usr/bin/python3 - Use /usr/bin/python3 in Jupyter notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM