Having trouble opening a virtual environment in python3.9.

huangapple go评论55阅读模式
英文:

Having trouble opening a virtual environment in python3.9

问题

我已经通过apt在我的Ubuntu 18.04.6 LTS上安装了Python 3.9。然后我尝试创建一个在3.9上运行的新虚拟环境,以下是我所做的过程:

$ python3.9 -m venv /home/user1/py3.9
Error: Command '['/home/user1/py3.9/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

为了解决这个问题,我尝试升级pip,但遇到了与distutils相关的错误,以下是该命令的输出:

$ python3.9 -m pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  ...
  ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

然后我使用命令 sudo apt install python3.9-distutils 安装了distutils,安装成功后,我能够升级pip。但是如果我尝试创建虚拟环境,仍然遇到了相同的 returned non-zero exit status 1 问题。我不确定我做错了什么,但我过去曾安装过Python 3.11,并且可以以相同的方式创建虚拟环境,根据我所记得。我现在不确定该怎么办。

英文:

I have installed python3.9 through apt in my Ubuntu 18.04.6 LTS. Then I was trying to create a new virtual environment that runs on 3.9. This is the process I did:

$ python3.9 -m venv /home/user1/py3.9
Error: Command '['/home/user1/py3.9/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

To remedy this I tried upgrading pip, which raised an error regarding distutils. Here was the output of that:

$ python3.9 -m pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 29, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
    from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

I then installed distutils using the command: sudo apt install python3.9-distutils, which was sucessful and after that I could upgrade pip.
But I'm still having the same problem of returned non-zero exit status 1 if I try to create the virtual environment. I'm not sure what I did wrong. But I did install python3.11 in the past and could create virtual environment the same way IIRC. I'm not sure what to do at this point.

答案1

得分: 0

只安装Python是不够的。
您需要执行多个步骤:

sudo apt install python3.9
sudo apt install python3.9-distutils
sudo apt install python3.9-venv
sudo apt install python3.9-dev

希望在此之后一切都能按预期工作。

英文:

Just installing python isn't enough.
You have to to multiple steps:

sudo apt install python3.9
sudo apt install python3.9-distutils
sudo apt install python3.9-venv
sudo apt install python3.9-dev

Hopefully, after that everything will work as intended.

huangapple
  • 本文由 发表于 2023年5月23日 00:19:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76308144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定