Python3.10源码venv已经改变

发布于 2025-01-20 18:23:57 字数 338 浏览 1 评论 0原文

我去了个人仓库做一些Python Leetcode,在将Kubuntu升级到22.04之后,我意识到当前的Venv不起作用。

我觉得我需要重新创建VENV。 安装了Python3.10-VENV,但我无法源自并激活它。

实际上,VENV/bin/Activate不再存在。

该文件夹仅包含

python python3 python3.10

我尝试过的三个文件,但没有骰子,

source venv/bin/python3.10

因此自然而然地源venv/bin/Activate无效。想法?

I went to do some python leetcode on a personal repo and after I upgraded my Kubuntu to 22.04 I realized the current venv wasn't working.

I had figured I would need to recreate the venv.
Installed python3.10-venv but I cant source and activate it.

In fact venv/bin/activate doesn't exist anymore.

The folder only contains three files

python python3 python3.10

I had tried but no dice

source venv/bin/python3.10

So naturally source venv/bin/activate doesn't work. Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

狼亦尘 2025-01-27 18:23:57

我安装了 Ubuntu 22.0.4,遇到了和你一样的问题,我用这种方式解决了这个问题。

安装 venv:

  1. sudo apt-get update

  2. sudo apt-get install python3-virtualenv

创建 venv:

  1. virtualenv --python=/usr/bin/python3.10 (VENV-NAME)
  2. python3.10 - m venv (VENV-NAME)
  3. 源(VENV-NAME)/bin/activate

检查&更新 pip:

  1. pip list
  2. 并更新 pip 例如(在我的电脑中):
    (/home/amin/Desktop/prog/Django/moein/coffeinrider.com/Project/A/(VENV-NAME)/bin/python3.10 -m pip install --upgrade pip)

I've installed Ubuntu 22.0.4 and I've had the same problem as yours and I solved that problem in this way.

install venv:

  1. sudo apt-get update

  2. sudo apt-get install python3-virtualenv

Create venv:

  1. virtualenv --python=/usr/bin/python3.10 (VENV-NAME)
  2. python3.10 -m venv (VENV-NAME)
  3. source (VENV-NAME)/bin/activate

check & update pip:

  1. pip list
  2. and update pip for example(in my pc):
    (/home/amin/Desktop/prog/Django/moein/coffeinrider.com/Project/A/(VENV-NAME)/bin/python3.10 -m pip install --upgrade pip)
稚然 2025-01-27 18:23:57

当尝试使用venv为Python创建虚拟设备时,必须使用已安装的Python版本,但必须使用venv库的版本系统也必须使用。这是设置虚拟环境的两个先决条件。

警告:我急忙这样做是因为我需要它,但请警告:这可能会破坏您的系统python,结果依靠它的应用程序可能会破坏。

我遇到的问题,符合给定的症状在这里,似乎是在尝试使用Python 3.10.8创建VENV时,使用了venv用于Python 3.8.10的模块。

因此,给定Python 3.8和Python 3.10已经使用apt安装,首先,我卸载了这些软件包:

sudo apt purge python3-venv python3.8-venv
sudo apt autoremove

然后我链接python3指向Python 3.10:

cd /usr/bin
sudo rm python3
sudo ln python3.10 python3

然后我安装了安装的VENV for Python3.10:

sudo apt install python3.10-venv

现在意味着为Python 3.8创建虚拟环境不起作用(因为Python3.8 VENV刚刚删除了)。我不确定是否有一种使它们都起作用的方法,而且我还没有尝试再次安装python3.8-venv并尝试两者,因为我需要我的3.10环境现在很快工作;-)。但是,在遵循Ubuntu 20内通常的升级路线时,似乎可能引入了一些冲突。

但是,Python 3.10的VENV现在应该按预期工作:

$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -V
Python 3.10.8
(.venv) $ pip install --upgrade pip
...
(.venv) $ pip list
Package    Version
---------- -------
pip        22.3
setuptools 63.2.0

When trying to create a virtual env using venv for Python, a version of Python that is already installed system-wide must be used, but a version of the venv library from the system must also be used. These are two pre-requisites for setting up a virtual environment.

WARNING: I did this in a hurry because I needed it but please be warned: this may break your system Python with a result that applications that rely on it may break.

The problem I had, matching symptoms given here, seems to be that when trying to create a venv using Python 3.10.8, the venv module for Python 3.8.10 was being used.

So, given Python 3.8 and Python 3.10 are already installed using apt, first of all I uninstalled these packages:

sudo apt purge python3-venv python3.8-venv
sudo apt autoremove

Then I linked python3 to point to Python 3.10:

cd /usr/bin
sudo rm python3
sudo ln python3.10 python3

Then I installed the venv for Python3.10:

sudo apt install python3.10-venv

This now means creating a virtual environment for Python 3.8 doesn't work (because Python3.8 venv has just been removed). I'm not sure if there is a means to have them both working, and I haven't yet tried to just install python3.8-venv again and try them both, as I need my 3.10 environment working quickly, right now ;-). But it seems possible there has been some conflict introduced when following the usual upgrade route within Ubuntu 20.

However, venv for Python 3.10 should now work as expected:

$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -V
Python 3.10.8
(.venv) $ pip install --upgrade pip
...
(.venv) $ pip list
Package    Version
---------- -------
pip        22.3
setuptools 63.2.0
安静被遗忘 2025-01-27 18:23:57

它已更新为source venv/local/bin/activate

It has been updated to source venv/local/bin/activate

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文