Python3.5 在 vi​​rtualenv 中声明 pip 安装,卸载时出现错误

Python3.5 在 vi​​rtualenv 中声明 pip 安装,卸载时出现错误
nmj@pc-nm:~$ sudo apt remove python3.5
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies.
 debconf : PreDepends: perl-base (>= 5.6.1-4) but it is not going to be installed
           Recommends: apt-utils (>= 0.5.1) but it is not going to be installed
           Recommends: debconf-i18n but it is not going to be installed
 init-system-helpers : Depends: perl-base (>= 5.20.1-3) but it is not going to be installed
 libacl1 : Depends: libattr1 (>= 1:2.4.46-8) but it is not going to be installed
 libedit2 : Depends: libtinfo5 (>= 6) but it is not going to be installed
 libsystemd0 : PreDepends: libgcrypt20 (>= 1.6.1) but it is not going to be installed
 libxml2 : Depends: libicu65 (>= 65.1-1~) but it is not going to be installed
 libzvbi0 : Depends: libpng12-0 (>= 1.2.13-4) but it is not going to be installed
 procps : Depends: libncurses5 (>= 6) but it is not going to be installed
          Depends: libncursesw5 (>= 6) but it is not going to be installed
          Depends: libprocps4 but it is not going to be installed
          Depends: libtinfo5 (>= 6) but it is not going to be installed
          Depends: initscripts
 psmisc : Depends: libtinfo5 (>= 6) but it is not going to be installed
 systemd : PreDepends: libgcrypt20 (>= 1.6.1) but it is not going to be installed
           Depends: libaudit1 (>= 1:2.2.1) but it is not going to be installed
           Depends: libblkid1 (>= 2.19.1) but it is not going to be installed
           Depends: libcryptsetup4 (>= 2:1.4.3) but it is not going to be installed
           Depends: libmount1 (>= 2.26.2) but it is not going to be installed
           Depends: libpam0g (>= 0.99.7.1) but it is not going to be installed
           Depends: util-linux (>= 2.27.1)
           Depends: mount (>= 2.26)
           Depends: adduser but it is not going to be installed
           Recommends: libpam-systemd but it is not going to be installed
           Recommends: dbus
 ucf : Depends: coreutils (>= 5.91)
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

以上是我的错误日志。我试图卸载 python3.5 以保留 python3.9,但我一直收到此错误。我需要帮助,我使用 ubuntu 16.04LTS,我正在尝试处理一个 django 项目,但即使在 venv 内部,pip 也会将其所有包解析到 python3.5 基础目录中,这变得非常烦人,因为经过数小时的修复搜索后,由于这个版本冲突,我不断遇到更多错误。

然后对于虚拟环境,每当我尝试使用 安装 django 时pip install django,它都无法安装 2.1.0 之前的版本。但我需要安装 3.1.7 我确实以 root 身份安装了 django 3 版本,但在这个特定的虚拟环境中,我觉得 python3.5 占用了 pip,所有安装都很混乱。

谢谢

答案1

从你的描述来看,我不太清楚你的问题。但我有一个想法,也许能帮到你。

你的系统安装了多少个版本的python?

如果你不知道,试试这个,

find /usr /lib* /home -type d \( -name "*site-packages" -or -name "*dist-packages" \)

这个想法是找到 Python 分发和包文件夹的所有位置。

/usr/lib/python2.7/dist-packages
/usr/lib/python3/dist-packages
/home/name/pyenv/versions/3.8.3/lib/python3.8/site-packages

然后你就会清楚地了解你的系统中编译了哪些版本的 Python。

现在,是时候获取它们的所有pips 了。(如果您不安装,其中一些可能没有)

find /bin /usr /lib* /home -type f -name "pip*" -executable

您可能会得到一些类似输出;

/usr/bin/pip3
/usr/bin/pip3.5
/home/NAME/pyenv/shims/pip3

使用以下命令逐一测试它们:

PATH-of-PIP --version

e.g.

/usr/bin/pip3 --version

知道这些pip链接指向哪里。

就您而言,由于您想使用版本python-3.9,因此您可以;

pip-full-path-for-3.9 install django

为了方便起见,您也可以将其永久添加到您的.bashrc文件中。我的建议是为其添加一个alias。或者创建一个符号链接。或者更改其名称,以便于记住使用(如果您确实确定的话)。

echo "alias pip3.9=pip-full-path-for-3.9" >> ~/.bashrc

答案2

我找到了一个解决方法。创建特定版本的虚拟环境非常简单

如何?

virtualenv venv --python=python3.9

从上面可以看出,python 3.9 将是其中唯一的版本

source venv/bin/activate

现在请使用以下内容确认您的无冲突区域

pip --version
pip3 --version

2 产生 1 个答案

python --version
python3 --version
python3.9 --version

以上 3 个结果产生 1 个答案。

现在对于从 pip 安装,你只需执行一个操作,就会pip install ... pip --freeze在 qn 中显示 venv 中的所有要求

希望这对某些人有帮助。

相关内容