我的 debian 操作系统已经进行了几次升级,现在版本为 11 (Bullseye)。我最初是从 开始的python2
,现在我不再想要它了——我只是想要python3
。我virtualenv
很久以前就安装了,当时我还在使用python2
.
我已经做了完整的dist-upgrade
:
$ sudo apt-get update
Hit:1 http://deb.debian.org/debian bullseye InRelease
Get:2 https://deb.nodesource.com/node_14.x bullseye InRelease [4,586 B]
Get:3 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Hit:4 http://deb.debian.org/debian bullseye-updates InRelease
Fetched 53.0 kB in 1s (49.9 kB/s)
Reading package lists... Done
$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
libts-dev
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
当我检查是否virtualenv
已安装时,它说是:
$ which virtualenv
/usr/local/bin/virtualenv
我尝试卸载它,但pip
告诉我它没有安装:
$ pip uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed
$ sudo pip uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed.
$ pip3 uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed
$ sudo pip3 uninstall virtualenv
WARNING: Skipping virtualenv as it is not installed.
我还尝试使用包管理器卸载,以防它是这样安装的
$ sudo apt-get remove virtualenv --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'virtualenv' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
但毕竟我仍然可以看到它已安装:
$ which virtualenv
/usr/local/bin/virtualenv
我想删除它的原因是当我尝试运行它时它出现错误。我正在考虑完全删除它并再次安装将解决此问题:
$ virtualenv .
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ModuleNotFoundError: No module named 'virtualenv'
我应该删除吗/usr/local/bin/virtualenv
?这似乎是个坏主意。如何virtualenv
使用包管理器删除?
更新 1 - 尝试virtualenv
使用安装pip3
安装成功但virtualenv
仍然无法运行,没有报错:
$ pip3 install virtualenv
Defaulting to user installation because normal site-packages is not writeable
Collecting virtualenv
Using cached virtualenv-20.25.1-py3-none-any.whl.metadata (4.4 kB)
Requirement already satisfied: distlib<1,>=0.3.7 in ./.local/lib/python3.9/site-packages (from virtualenv) (0.3.8)
Requirement already satisfied: filelock<4,>=3.12.2 in ./.local/lib/python3.9/site-packages (from virtualenv) (3.13.3)
Requirement already satisfied: platformdirs<5,>=3.9.1 in ./.local/lib/python3.9/site-packages (from virtualenv) (4.2.0)
Using cached virtualenv-20.25.1-py3-none-any.whl (3.8 MB)
Installing collected packages: virtualenv
WARNING: The script virtualenv is installed in '/home/me/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed virtualenv-20.25.1
$ which virtualenv
/usr/local/bin/virtualenv
$ virtualenv --version
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/home/me/.local/lib/python3.9/site-packages/virtualenv/__init__.py)
$ virtualenv .
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/home/me/.local/lib/python3.9/site-packages/virtualenv/__init__.py)
现在virtualenv
存在于文件系统上的两个位置:
$ which virtualenv
/usr/local/bin/virtualenv
$ sudo find /usr/ -iname "virtualenv" | grep bin
/usr/local/bin/virtualenv
$ sudo find /home/me/.local/ -iname "virtualenv" | grep bin
/home/me/.local/bin/virtualenv
$ ls -l /home/me/.local/bin/virtualenv
-rwxr-xr-x 1 me me 238 Apr 7 13:06 /home/me/.local/bin/virtualenv