Ubuntu版本升级后终端启动报错virtualenvwrapper模块缺失及24.04版本下安装方案选择疑问
Ubuntu版本升级后终端启动报错virtualenvwrapper模块缺失及24.04版本下安装方案选择疑问
最近把Ubuntu从20.04升级到22.04后,每次打开终端都会弹出一堆错误提示,具体内容如下:
/usr/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper') virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is set properly.
我检查了自己~/.bashrc里的virtualenvwrapper配置,内容是这样的:
#Virtualenvwrapper settings: export WORKON_HOME=$HOME/.virtualenvs VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 . /usr/local/bin/virtualenvwrapper.sh
我还注意到最后一行的点后面有个空格,不确定是不是这个空格引发的问题?另外我也确认了系统里Python3的指向:
mike@orac:/usr/bin$ ls -la /usr/bin/python3 lrwxrwxrwx 1 root root 10 Aug 18 22:39 /usr/bin/python3 -> python3.10
后来我又把系统升级到了24.04,结果之前的解决办法完全不管用了。当我尝试用pip3 install -U virtualenvwrapper重新安装时,直接弹出了"externally-managed-environment"的错误:
error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.12/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
这时候我就有点纠结了:virtualenvwrapper到底是Debian官方打包的软件,还是非官方的第三方软件?我到底应该用apt install python3-virtualenvwrapper通过系统包管理器安装,还是用pipx install virtualenvwrapper来安装?
琢磨了一会儿后,我最终选择执行sudo apt install virtualenvwrapper来解决这个问题。
备注:内容来源于stack exchange,提问作者Jedi
相关产品推荐
相关产品推荐

